Skip to content

Commit

Permalink
Adding a . as a valid character for Modules' name.
Browse files Browse the repository at this point in the history
When a `Module` is deleted, the `NMC` controller is removing the labels
for this `Module` in the `NMC` object.

As long as those labels for a specific module exists, the module's
finalizer will not be removed upon module deletion and the module will
keep hanging forever if deleted.

When a module is created with a `.` in its name, the created label for
`NMC` doesn't match the expected regexp for this label and, therefore, not
removed upon module's deletion.

Adding the `.` will allow the label to match the regexp, be removed upon
deletion and deleting the module gracefully.

Signed-off-by: Yoni Bettan <[email protected]>
  • Loading branch information
ybettan committed Jan 9, 2025
1 parent 7c5569e commit 0b6d54d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/nmc/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

var (
reConfiguredLabel = regexp.MustCompile(`^beta\.kmm\.node\.kubernetes\.io/([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)\.module-configured$`)
reInUseLabel = regexp.MustCompile(`^beta\.kmm\.node\.kubernetes\.io/([a-zA-Z0-9-]+)\.([a-zA-Z0-9-]+)\.module-in-use$`)
reConfiguredLabel = regexp.MustCompile(`^beta\.kmm\.node\.kubernetes\.io/([a-zA-Z0-9-]+)\.([a-zA-Z0-9-\.]+)\.module-configured$`)
reInUseLabel = regexp.MustCompile(`^beta\.kmm\.node\.kubernetes\.io/([a-zA-Z0-9-]+)\.([a-zA-Z0-9-\.]+)\.module-in-use$`)
)

func IsModuleConfiguredLabel(s string) (bool, string, string) {
Expand Down
20 changes: 20 additions & 0 deletions internal/nmc/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ var _ = Describe("ModuleConfiguredLabel", func() {
Equal("beta.kmm.node.kubernetes.io/a.b.module-configured"),
)
})

It("should work as expected with a dot in the name", func() {

Expect(
ModuleConfiguredLabel("a", "b.1"),
).To(
Equal("beta.kmm.node.kubernetes.io/a.b.1.module-configured"),
)
})
})

var _ = Describe("ModuleInUseLabel", func() {
Expand All @@ -25,6 +34,15 @@ var _ = Describe("ModuleInUseLabel", func() {
Equal("beta.kmm.node.kubernetes.io/a.b.module-in-use"),
)
})

It("should work as expected with a dot in the name", func() {

Expect(
ModuleInUseLabel("a", "b.1"),
).To(
Equal("beta.kmm.node.kubernetes.io/a.b.1.module-in-use"),
)
})
})

var _ = Describe("IsModuleConfiguredLabel", func() {
Expand All @@ -47,6 +65,7 @@ var _ = Describe("IsModuleConfiguredLabel", func() {
Entry(nil, "beta.kmm.node.kubernetes.io/..module-configured", false, "", ""),
Entry(nil, "beta.kmm.node.kubernetes.io/a123.b456.module-configured", true, "a123", "b456"),
Entry(nil, "beta.kmm.node.kubernetes.io/with-hypen.withouthypen.module-configured", true, "with-hypen", "withouthypen"),
Entry(nil, "beta.kmm.node.kubernetes.io/my-namespace.my-name.stil-my-name.module-configured", true, "my-namespace", "my-name.stil-my-name"),
)
})

Expand All @@ -70,5 +89,6 @@ var _ = Describe("IsModuleInUseLabel", func() {
Entry(nil, "beta.kmm.node.kubernetes.io/..module-in-use", false, "", ""),
Entry(nil, "beta.kmm.node.kubernetes.io/a123.b456.module-in-use", true, "a123", "b456"),
Entry(nil, "beta.kmm.node.kubernetes.io/with-hypen.withouthypen.module-in-use", true, "with-hypen", "withouthypen"),
Entry(nil, "beta.kmm.node.kubernetes.io/my-namespace.my-name.stil-my-name.module-in-use", true, "my-namespace", "my-name.stil-my-name"),
)
})

0 comments on commit 0b6d54d

Please sign in to comment.