Skip to content
Draft
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
69 changes: 53 additions & 16 deletions test/openshift/e2e/ginkgo/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ const (

var NamespaceLabels = map[string]string{E2ETestLabelsKey: E2ETestLabelsValue}

// Retrieve installation namespace
func GetInstallationNamespace() string {

k8sClient, _ := utils.GetE2ETestKubeClient()
installationNamespace := "openshift-operators"

sub := &olmv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-gitops-operator",
Namespace: installationNamespace,
},
}

if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub); err != nil {

installationNamespace = "openshift-gitops-operator"

sub = &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace}}

if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub); err != nil {
return ""
}
}
return installationNamespace
}

func EnsureParallelCleanSlate() {

// Increase the maximum length of debug output, for when tests fail
Expand Down Expand Up @@ -212,7 +238,9 @@ func RemoveDynamicPluginFromCSV(ctx context.Context, k8sClient client.Client) er

var csv *olmv1alpha1.ClusterServiceVersion
var csvList olmv1alpha1.ClusterServiceVersionList
Expect(k8sClient.List(ctx, &csvList, client.InNamespace("openshift-gitops-operator"))).To(Succeed())
installationNamespace := GetInstallationNamespace()
Expect(installationNamespace).ToNot(BeNil(), "if you see this, it likely means, either: A) the operator is not installed via OLM (and you meant to install it), OR B) you are running the operator locally via 'make run', and thus should specify LOCAL_RUN=true env var when calling the test")
Expect(k8sClient.List(ctx, &csvList, client.InNamespace(installationNamespace))).To(Succeed())

for idx := range csvList.Items {
idxCSV := csvList.Items[idx]
Expand Down Expand Up @@ -374,8 +402,10 @@ func GetEnvInOperatorSubscriptionOrDeployment(key string) (*string, error) {
return nil, nil
}

installationNamespace := GetInstallationNamespace()

if EnvNonOLM() {
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}}
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: installationNamespace}}

return deploymentFixture.GetEnv(depl, key)

Expand All @@ -395,7 +425,7 @@ func GetEnvInOperatorSubscriptionOrDeployment(key string) (*string, error) {

} else {

sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"}}
sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace}}
if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub); err != nil {
return nil, err
}
Expand All @@ -411,12 +441,14 @@ func SetEnvInOperatorSubscriptionOrDeployment(key string, value string) {

k8sClient, _ := utils.GetE2ETestKubeClient()

installationNamespace := GetInstallationNamespace()

if EnvNonOLM() {
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}}
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: installationNamespace}}

deploymentFixture.SetEnv(depl, key, value)

WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient)
WaitForAllDeploymentsInTheNamespaceToBeReady(installationNamespace, k8sClient)

} else if EnvCI() {

Expand All @@ -430,7 +462,7 @@ func SetEnvInOperatorSubscriptionOrDeployment(key string, value string) {

} else {

sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"}}
sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace}}
Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub)).To(Succeed())

subscriptionFixture.SetEnv(sub, key, value)
Expand All @@ -448,12 +480,14 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {
return err
}

installationNamespace := GetInstallationNamespace()

if EnvNonOLM() {
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}}
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: installationNamespace}}

deploymentFixture.RemoveEnv(depl, key)

WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient)
WaitForAllDeploymentsInTheNamespaceToBeReady(installationNamespace, k8sClient)

} else if EnvCI() {

Expand All @@ -471,7 +505,7 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {

} else {

sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"}}
sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace}}
if err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub); err != nil {
return err
}
Expand All @@ -486,7 +520,8 @@ func RemoveEnvFromOperatorSubscriptionOrDeployment(key string) error {

func GetSubscriptionInEnvCIEnvironment(k8sClient client.Client) (*olmv1alpha1.Subscription, error) {
subscriptionList := olmv1alpha1.SubscriptionList{}
if err := k8sClient.List(context.Background(), &subscriptionList, client.InNamespace("openshift-gitops-operator")); err != nil {

if err := k8sClient.List(context.Background(), &subscriptionList, client.InNamespace(GetInstallationNamespace())); err != nil {
return nil, err
}

Expand All @@ -510,12 +545,14 @@ func RestoreSubcriptionToDefault() {
k8sClient, _, err := utils.GetE2ETestKubeClientWithError()
Expect(err).ToNot(HaveOccurred())

installationNamespace := GetInstallationNamespace()

// optionalEnvVarsToRemove is a non-exhaustive list of environment variables that are known to be added to Subscription or operator Deployment by tests
optionalEnvVarsToRemove := []string{"DISABLE_DEFAULT_ARGOCD_CONSOLELINK", "CONTROLLER_CLUSTER_ROLE", "SERVER_CLUSTER_ROLE", "ARGOCD_LABEL_SELECTOR", "ALLOW_NAMESPACE_MANAGEMENT_IN_NAMESPACE_SCOPED_INSTANCES"}

if EnvNonOLM() {

depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: "openshift-gitops-operator"}}
depl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator-controller-manager", Namespace: installationNamespace}}

for _, envKey := range optionalEnvVarsToRemove {
deploymentFixture.RemoveEnv(depl, envKey)
Expand All @@ -535,26 +572,26 @@ func RestoreSubcriptionToDefault() {
subscriptionFixture.RemoveSpecConfig(sub)
}

err = waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient)
err = waitForAllEnvVarsToBeRemovedFromDeployments(installationNamespace, optionalEnvVarsToRemove, k8sClient)
Expect(err).ToNot(HaveOccurred())

WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient)
WaitForAllDeploymentsInTheNamespaceToBeReady(installationNamespace, k8sClient)

} else if EnvLocalRun() {
// When running locally, there are no cluster resources to clean up

} else {

sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"}}
sub := &olmv1alpha1.Subscription{ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace}}
err := k8sClient.Get(context.Background(), client.ObjectKeyFromObject(sub), sub)
Expect(err).ToNot(HaveOccurred())

subscriptionFixture.RemoveSpecConfig(sub)

err = waitForAllEnvVarsToBeRemovedFromDeployments("openshift-gitops-operator", optionalEnvVarsToRemove, k8sClient)
err = waitForAllEnvVarsToBeRemovedFromDeployments(installationNamespace, optionalEnvVarsToRemove, k8sClient)
Expect(err).ToNot(HaveOccurred())

WaitForAllDeploymentsInTheNamespaceToBeReady("openshift-gitops-operator", k8sClient)
WaitForAllDeploymentsInTheNamespaceToBeReady(installationNamespace, k8sClient)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
}

By("run oc command to verify our ability to delete resourcequotas")
res, err := osFixture.ExecCommand("oc", "auth", "can-i", "delete", "resourcequotas", "-n", "openshift-gitops", "--as", "system:serviceaccount:openshift-gitops-operator:openshift-gitops-operator-controller-manager")
res, err := osFixture.ExecCommand("oc", "auth", "can-i", "delete", "resourcequotas", "-n", "openshift-gitops", "--as", "system:serviceaccount:"+fixture.GetInstallationNamespace()+":openshift-gitops-operator-controller-manager")
Expect(err).ToNot(HaveOccurred())
Expect(strings.TrimSpace(res)).To(Equal("yes"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
Context("1-077_validate_disable_dex_removed", func() {

var (
k8sClient client.Client
ctx context.Context
k8sClient client.Client
ctx context.Context
installationNamespace = fixture.GetInstallationNamespace()
)

BeforeEach(func() {
Expand Down Expand Up @@ -66,7 +67,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {

} else {
subscription := &olmv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: "openshift-gitops-operator"},
ObjectMeta: metav1.ObjectMeta{Name: "openshift-gitops-operator", Namespace: installationNamespace},
}
Expect(subscription).Should(k8sFixture.ExistByName())

Expand All @@ -80,7 +81,7 @@ var _ = Describe("GitOps Operator Parallel E2E Tests", func() {

csv := &olmv1alpha1.ClusterServiceVersion{ObjectMeta: metav1.ObjectMeta{
Name: operatorNameVersion,
Namespace: "openshift-gitops-operator",
Namespace: installationNamespace,
}}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(csv), csv)).To(Succeed())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
operatorControllerDepl := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-gitops-operator-controller-manager",
Namespace: "openshift-gitops-operator", // The original kuttl test was 'openshift-operators'
Namespace: fixture.GetInstallationNamespace(), // The original kuttl test was 'openshift-operators'
},
}
Eventually(operatorControllerDepl).Should(k8sFixture.ExistByName())
Expand Down Expand Up @@ -151,7 +151,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
Eventually(openshiftGitopsArgoCD, "3m", "5s").Should(k8sFixture.ExistByName())
Eventually(openshiftGitopsArgoCD, "5m", "5s").Should(argocdFixture.BeAvailable())

By("verifying deployment and statefulset have expected number of replicas, including the repo server which should have 2")
By("verifying deployment and statefulset have expected number of replicas")
deploymentsToVerify := []string{
"openshift-gitops-server",
"openshift-gitops-redis",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var _ = Describe("GitOps Operator Sequential E2E Tests", func() {

Context("1-035-validate_argocd_secret_repopulate", func() {
Context("1-035_validate_argocd_secret_repopulate", func() {

var (
ctx context.Context
Expand Down Expand Up @@ -71,7 +71,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
depl := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-gitops-operator-controller-manager",
Namespace: "openshift-gitops-operator",
Namespace: fixture.GetInstallationNamespace(),
},
}
Eventually(depl, "1m", "5s").Should(deploymentFixture.HaveReadyReplicas(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
})

AfterEach(func() {
fixture.OutputDebugOnFail("test-1-56-target", "test-1-56-custom", "test-1-56-target-2", "test-1-56-custom-2", "openshift-gitops-operator")
fixture.OutputDebugOnFail("test-1-56-target", "test-1-56-custom", "test-1-56-target-2", "test-1-56-custom-2", fixture.GetInstallationNamespace())
})

It("verifies that managed-by works as expected and that REMOVE_MANAGED_BY_LABEL_ON_ARGOCD_DELETION will remove managed-by label when the related ArgoCD instance is deleted", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
// Find CSV
var csv *olmv1alpha1.ClusterServiceVersion
var csvList olmv1alpha1.ClusterServiceVersionList
Expect(k8sClient.List(ctx, &csvList, client.InNamespace("openshift-gitops-operator"))).To(Succeed())
Expect(k8sClient.List(ctx, &csvList, client.InNamespace(fixture.GetInstallationNamespace()))).To(Succeed())

for idx := range csvList.Items {
idxCSV := csvList.Items[idx]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
return
}

var installationNamespace = fixture.GetInstallationNamespace()

sm := &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "openshift-gitops-operator-metrics-monitor",
Namespace: "openshift-gitops-operator",
Namespace: installationNamespace,
},
}
Eventually(sm).Should(k8sFixture.ExistByName())
Expand All @@ -43,7 +45,7 @@ var _ = Describe("GitOps Operator Sequential E2E Tests", func() {
SafeTLSConfig: monitoringv1.SafeTLSConfig{
CA: monitoringv1.SecretOrConfigMap{},
Cert: monitoringv1.SecretOrConfigMap{},
ServerName: "openshift-gitops-operator-metrics-service.openshift-gitops-operator.svc",
ServerName: "openshift-gitops-operator-metrics-service." + installationNamespace + ".svc",
},
CAFile: "/etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt",
},
Expand Down