Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,14 +584,22 @@ func (d *Deployer) ensureNamespaceExists(namespace string) error {
}

d.logger.Infof("Creating namespace %s", namespace)

_, err := d.runKubectl(context.Background(), KubectlOptions{
Args: []string{"create", "namespace", namespace},
})
if err != nil {
return fmt.Errorf("failed to create namespace: %w", err)
}

// Label namespace as managed by roxie since we just created it
_, err = d.runKubectl(context.Background(), KubectlOptions{
Args: []string{"label", "namespace", namespace,
"app.kubernetes.io/managed-by=roxie", "--overwrite"},
})
if err != nil {
d.logger.Warningf("failed to label namespace %s: %v", namespace, err)
}

return nil
}

Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ func TestDeployBothSimple(t *testing.T) {
args := append([]string{roxieBinary, "deploy", "--early-readiness", "both", "--envrc", envrcPath}, commonDeployArgsNoPortForward...)
runCommand(t, deployTimeout*2, nil, args...)

// Verify namespaces exist
// Verify namespaces exist and have managed-by labels
t.Log("Verifying namespace: acs-central")
verifyNamespaceExists(t, "acs-central")
verifyNamespaceHasLabel(t, "acs-central", "app.kubernetes.io/managed-by", "roxie")

t.Log("Verifying namespace: acs-sensor")
verifyNamespaceExists(t, "acs-sensor")
verifyNamespaceHasLabel(t, "acs-sensor", "app.kubernetes.io/managed-by", "roxie")

// Brief pause before cleanup
time.Sleep(5 * time.Second)
Expand Down
24 changes: 23 additions & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ func verifyNamespaceExists(t *testing.T, namespace string) {
}
}

func verifyNamespaceHasLabel(t *testing.T, namespace, key, value string) {
t.Helper()

cmd := exec.Command("kubectl", "get", "namespace", namespace,
"-o", "jsonpath={.metadata.labels['"+key+"']}")
Comment thread
AlexVulaj marked this conversation as resolved.
output, err := cmd.Output()
if err != nil {
t.Fatalf("Failed to get label %s from namespace %s: %v", key, namespace, err)
}

actualValue := strings.TrimSpace(string(output))
if actualValue != value {
t.Fatalf("Namespace %s has label %s=%s, expected %s", namespace, key, actualValue, value)
}
}

func doesDeploymentExist(t *testing.T, namespace string, name string) bool {
t.Helper()

Expand Down Expand Up @@ -272,12 +288,14 @@ func TestDeployCentralAndSecuredCluster(t *testing.T) {
args = append([]string{roxieBinary, "deploy", "--early-readiness", "secured-cluster"}, commonDeployArgsNoPortForward...)
runCommand(t, deployTimeout, envrcEnv, args...)

// Verify namespaces
// Verify namespaces and labels
t.Log("Verifying namespace: acs-central")
verifyNamespaceExists(t, "acs-central")
verifyNamespaceHasLabel(t, "acs-central", "app.kubernetes.io/managed-by", "roxie")

t.Log("Verifying namespace: acs-sensor")
verifyNamespaceExists(t, "acs-sensor")
verifyNamespaceHasLabel(t, "acs-sensor", "app.kubernetes.io/managed-by", "roxie")

// Brief pause before next test
time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -350,9 +368,11 @@ func TestDeployBothComponentsTogether(t *testing.T) {

t.Log("Verifying namespace: acs-central")
verifyNamespaceExists(t, "acs-central")
verifyNamespaceHasLabel(t, "acs-central", "app.kubernetes.io/managed-by", "roxie")

t.Log("Verifying namespace: acs-sensor")
verifyNamespaceExists(t, "acs-sensor")
verifyNamespaceHasLabel(t, "acs-sensor", "app.kubernetes.io/managed-by", "roxie")

// Verify Central has the pause-reconcile annotation.
t.Log("Verifying pause-reconcile annotation on Central CR")
Expand Down Expand Up @@ -420,9 +440,11 @@ func TestDeployCentralAndSecuredClusterViaHelm(t *testing.T) {

t.Log("Verifying namespace: acs-central")
verifyNamespaceExists(t, "acs-central")
verifyNamespaceHasLabel(t, "acs-central", "app.kubernetes.io/managed-by", "roxie")

t.Log("Verifying namespace: acs-sensor")
verifyNamespaceExists(t, "acs-sensor")
verifyNamespaceHasLabel(t, "acs-sensor", "app.kubernetes.io/managed-by", "roxie")
}

func verifyAnnotation(t *testing.T, resourceType, resourceName, namespace, annotationKey, expectedValue string) {
Expand Down