Skip to content

Commit f97a356

Browse files
committed
ROX-27130: Fix tests
1 parent c4a553e commit f97a356

File tree

3 files changed

+187
-61
lines changed

3 files changed

+187
-61
lines changed

e2e/e2e_canary_upgrade_test.go

Lines changed: 170 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@ package e2e
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"strings"
89

10+
argocd "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
911
. "github.com/onsi/ginkgo/v2"
1012
. "github.com/onsi/gomega"
11-
"github.com/stackrox/acs-fleet-manager/e2e/testutil"
12-
"github.com/stackrox/acs-fleet-manager/fleetshard/pkg/central/operator"
13-
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
14-
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
15-
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/gitops"
16-
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
17-
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
18-
fmImpl "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"
19-
"github.com/stackrox/acs-fleet-manager/pkg/features"
2013
"github.com/stackrox/rox/operator/api/v1alpha1"
2114
appsv1 "k8s.io/api/apps/v1"
2215
v1 "k8s.io/api/core/v1"
2316
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
2417
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/apimachinery/pkg/runtime"
2519
"k8s.io/apimachinery/pkg/util/sets"
2620
verticalpodautoscalingv1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
2721
ctrlClient "sigs.k8s.io/controller-runtime/pkg/client"
2822
"sigs.k8s.io/yaml"
23+
24+
"github.com/stackrox/acs-fleet-manager/e2e/testutil"
25+
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/constants"
26+
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
27+
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/gitops"
28+
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/services"
29+
"github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager"
30+
fmImpl "github.com/stackrox/acs-fleet-manager/pkg/client/fleetmanager/impl"
31+
"github.com/stackrox/acs-fleet-manager/pkg/features"
2932
)
3033

3134
const (
@@ -78,20 +81,20 @@ var _ = Describe("Fleetshard-sync Targeted Upgrade", Ordered, func() {
7881

7982
It("should deploy operator 1 "+operator1DeploymentName, func() {
8083
// update gitops config to install one operator
81-
config := gitops.Config{
82-
RHACSOperators: operator.OperatorConfigs{
83-
CRDURLs: defaultCRDUrls,
84-
Configs: []operator.OperatorConfig{operatorConfig1},
85-
},
84+
config := defaultGitopsConfig()
85+
config.Applications = []argocd.Application{
86+
crdsApplication(),
87+
operatorsApplication(operatorConfig1),
8688
}
89+
8790
Expect(putGitopsConfig(ctx, config)).To(Succeed())
8891
Eventually(assertDeployedOperators(ctx, operator1DeploymentName)).
8992
WithTimeout(waitTimeout).
9093
WithPolling(defaultPolling).
9194
Should(Succeed())
9295
})
9396

94-
It("should run operator 1 with central label selector "+operatorConfig1.GetCentralLabelSelector(), func() {
97+
It("should run operator 1 with central label selector "+operatorConfig1.CentralLabelSelector, func() {
9598
Eventually(operatorMatchesConfig(ctx, operatorConfig1)).
9699
WithTimeout(waitTimeout).
97100
WithPolling(defaultPolling).
@@ -100,48 +103,48 @@ var _ = Describe("Fleetshard-sync Targeted Upgrade", Ordered, func() {
100103

101104
It("should deploy two operators in different versions", func() {
102105
// add a second operator version to the gitops config
103-
config := gitops.Config{
104-
RHACSOperators: operator.OperatorConfigs{
105-
CRDURLs: defaultCRDUrls,
106-
Configs: []operator.OperatorConfig{operatorConfig1, operatorConfig2},
107-
},
106+
config := defaultGitopsConfig()
107+
config.Applications = []argocd.Application{
108+
crdsApplication(),
109+
operatorsApplication(operatorConfig1, operatorConfig2),
108110
}
111+
109112
Expect(putGitopsConfig(ctx, config)).To(Succeed())
110113
Eventually(assertDeployedOperators(ctx, operator1DeploymentName, operator2DeploymentName)).
111114
WithTimeout(waitTimeout).
112115
WithPolling(defaultPolling).
113116
Should(Succeed())
114117
})
115118

116-
It("should deploy operator 1 with label selector "+operatorConfig1.GetCentralLabelSelector(), func() {
119+
It("should deploy operator 1 with label selector "+operatorConfig1.CentralLabelSelector, func() {
117120
Eventually(operatorMatchesConfig(ctx, operatorConfig1)).
118121
WithTimeout(waitTimeout).
119122
WithPolling(defaultPolling).
120123
Should(Succeed())
121124
})
122125

123-
It("should deploy operator 2 with label selector "+operatorConfig2.GetCentralLabelSelector(), func() {
126+
It("should deploy operator 2 with label selector "+operatorConfig2.CentralLabelSelector, func() {
124127
Eventually(operatorMatchesConfig(ctx, operatorConfig2)).
125128
WithTimeout(waitTimeout).
126129
WithPolling(defaultPolling).
127130
Should(Succeed())
128131
})
129132

130133
It("should delete operator 2 and only run operator 1", func() {
131-
config := gitops.Config{
132-
RHACSOperators: operator.OperatorConfigs{
133-
CRDURLs: defaultCRDUrls,
134-
Configs: []operator.OperatorConfig{operatorConfig1},
135-
},
134+
config := defaultGitopsConfig()
135+
config.Applications = []argocd.Application{
136+
crdsApplication(),
137+
operatorsApplication(operatorConfig1),
136138
}
139+
137140
Expect(putGitopsConfig(ctx, config)).To(Succeed())
138141
Eventually(assertDeployedOperators(ctx, operator1DeploymentName)).
139142
WithTimeout(waitTimeout).
140143
WithPolling(defaultPolling).
141144
Should(Succeed())
142145
})
143146

144-
It("should deploy operator 1 with label selector "+operatorConfig1.GetCentralLabelSelector(), func() {
147+
It("should deploy operator 1 with label selector "+operatorConfig1.CentralLabelSelector, func() {
145148
Eventually(operatorMatchesConfig(ctx, operatorConfig1)).
146149
WithTimeout(waitTimeout).
147150
WithPolling(defaultPolling).
@@ -157,7 +160,10 @@ var _ = Describe("Fleetshard-sync Targeted Upgrade", Ordered, func() {
157160
It("run only one operator with version: "+operatorVersion1, func() {
158161
Expect(updateGitopsConfig(ctx, func(config gitops.Config) gitops.Config {
159162
config = defaultGitopsConfig()
160-
config.RHACSOperators.Configs = []operator.OperatorConfig{operatorConfig1}
163+
config.Applications = []argocd.Application{
164+
crdsApplication(),
165+
operatorsApplication(operatorConfig1),
166+
}
161167
config.TenantResources.Overrides = []gitops.TenantResourceOverride{
162168
overrideAllCentralsToBeReconciledByOperator(operatorConfig1),
163169
overrideAllCentralsToUseMinimalResources(),
@@ -195,7 +201,10 @@ var _ = Describe("Fleetshard-sync Targeted Upgrade", Ordered, func() {
195201
It("upgrade central", func() {
196202
Expect(updateGitopsConfig(ctx, func(config gitops.Config) gitops.Config {
197203
config = defaultGitopsConfig()
198-
config.RHACSOperators.Configs = []operator.OperatorConfig{operatorConfig1, operatorConfig2}
204+
config.Applications = []argocd.Application{
205+
crdsApplication(),
206+
operatorsApplication(operatorConfig1, operatorConfig2),
207+
}
199208
config.TenantResources.Overrides = []gitops.TenantResourceOverride{
200209
overrideAllCentralsToBeReconciledByOperator(operatorConfig2),
201210
overrideAllCentralsToUseMinimalResources(),
@@ -378,11 +387,11 @@ func updateGitopsConfig(ctx context.Context, updateFn func(config gitops.Config)
378387

379388
}
380389

381-
func operatorConfigForVersion(version string) operator.OperatorConfig {
382-
return operator.OperatorConfig{
383-
"deploymentName": getDeploymentName(version),
384-
"image": fmt.Sprintf("quay.io/rhacs-eng/stackrox-operator:%s", version),
385-
"centralLabelSelector": fmt.Sprintf("rhacs.redhat.com/version-selector=%s", version),
390+
func operatorConfigForVersion(version string) OperatorConfig {
391+
return OperatorConfig{
392+
DeploymentName: getDeploymentName(version),
393+
Image: fmt.Sprintf("quay.io/rhacs-eng/stackrox-operator:%s", version),
394+
CentralLabelSelector: fmt.Sprintf("rhacs.redhat.com/version-selector=%s", version),
386395
}
387396
}
388397

@@ -394,7 +403,7 @@ func getOperatorDeployments(ctx context.Context) ([]appsv1.Deployment, error) {
394403
deployments := appsv1.DeploymentList{}
395404
labels := map[string]string{"app": "rhacs-operator"}
396405
err := k8sClient.List(ctx, &deployments,
397-
ctrlClient.InNamespace(operator.ACSOperatorNamespace),
406+
ctrlClient.InNamespace("rhacs"),
398407
ctrlClient.MatchingLabels(labels))
399408
if err != nil {
400409
return nil, err
@@ -465,22 +474,28 @@ func validateDeployment(deployment *appsv1.Deployment, assertions ...deploymentA
465474
return nil
466475
}
467476

468-
func operatorMatchesConfig(ctx context.Context, config operator.OperatorConfig) func() error {
477+
type OperatorConfig struct {
478+
DeploymentName string
479+
Image string
480+
CentralLabelSelector string
481+
}
482+
483+
func operatorMatchesConfig(ctx context.Context, config OperatorConfig) func() error {
469484
return func() error {
470-
deploy, err := getDeployment(ctx, operator.ACSOperatorNamespace, config.GetDeploymentName())
485+
deploy, err := getDeployment(ctx, "rhacs", config.DeploymentName)
471486
if err != nil {
472-
println("Got err", err.Error(), config.GetDeploymentName())
487+
println("Got err", err.Error(), config.DeploymentName)
473488
return err
474489
}
475490
return validateDeployment(deploy,
476-
operatorHasImageAssertion(config.GetImage()),
477-
operatorHasCentralLabelSelectorAssertion(config.GetCentralLabelSelector()),
491+
operatorHasImageAssertion(config.Image),
492+
operatorHasCentralLabelSelectorAssertion(config.CentralLabelSelector),
478493
)
479494
}
480495
}
481496

482-
func getLabelAndVersionFromOperatorConfig(operatorConfig operator.OperatorConfig) (string, string, error) {
483-
selector := operatorConfig.GetCentralLabelSelector()
497+
func getLabelAndVersionFromOperatorConfig(operatorConfig OperatorConfig) (string, string, error) {
498+
selector := operatorConfig.CentralLabelSelector
484499
selectorParts := strings.Split(selector, "=")
485500
if len(selectorParts) != 2 {
486501
return "", "", fmt.Errorf("invalid selector %s", selector)
@@ -490,7 +505,7 @@ func getLabelAndVersionFromOperatorConfig(operatorConfig operator.OperatorConfig
490505
return versionLabelKey, versionLabelValue, nil
491506
}
492507

493-
func overrideAllCentralsToBeReconciledByOperator(operatorConfig operator.OperatorConfig) gitops.TenantResourceOverride {
508+
func overrideAllCentralsToBeReconciledByOperator(operatorConfig OperatorConfig) gitops.TenantResourceOverride {
494509
return overrideAllCentralsWithPatch(reconciledByOperatorPatch(operatorConfig))
495510
}
496511

@@ -512,7 +527,7 @@ func overrideCentralWithPatch(centralID, patch string) gitops.TenantResourceOver
512527
}
513528
}
514529

515-
func reconciledByOperatorPatch(operatorConfig operator.OperatorConfig) string {
530+
func reconciledByOperatorPatch(operatorConfig OperatorConfig) string {
516531
_, value, err := getLabelAndVersionFromOperatorConfig(operatorConfig)
517532
if err != nil {
518533
panic(err)
@@ -619,22 +634,29 @@ func tenantResourcesWithCentralVpaEnabled() string {
619634
return `centralVpaEnabled: true`
620635
}
621636

637+
func mustJson(obj interface{}) []byte {
638+
b, err := json.Marshal(obj)
639+
Expect(err).ToNot(HaveOccurred())
640+
return b
641+
}
642+
622643
func defaultGitopsConfig() gitops.Config {
623644
return gitops.Config{
624-
TenantResources: gitops.TenantResourceConfig{
625-
Default: defaultTenantResourceValues(),
626-
},
627-
RHACSOperators: operator.OperatorConfigs{
628-
CRDURLs: defaultCRDUrls,
629-
Configs: []operator.OperatorConfig{
630-
{
631-
"deploymentName": "rhacs-operator-dev",
632-
"image": "quay.io/rhacs-eng/stackrox-operator:4.5.4",
633-
"centralLabelSelector": "rhacs.redhat.com/version-selector=dev",
634-
"securedClusterReconcilerEnabled": false,
635-
},
636-
},
637-
},
645+
TenantResources: defaultTenantResources(),
646+
Applications: defaultApplications(),
647+
}
648+
}
649+
650+
func defaultTenantResources() gitops.TenantResourceConfig {
651+
return gitops.TenantResourceConfig{
652+
Default: defaultTenantResourceValues(),
653+
}
654+
}
655+
656+
func defaultApplications() []argocd.Application {
657+
return []argocd.Application{
658+
crdsApplication(),
659+
operatorsApplication(operator462()),
638660
}
639661
}
640662

@@ -645,3 +667,92 @@ func restoreDefaultGitopsConfig() error {
645667
}
646668
return putGitopsConfig(context.Background(), defaultConfig)
647669
}
670+
671+
func operator462() OperatorConfig {
672+
return OperatorConfig{
673+
DeploymentName: "rhacs-operator-4.6.2",
674+
Image: "registry.redhat.io/advanced-cluster-security/rhacs-rhel8-operator@sha256:a96572d0df791da60763dec4b4f0f52124772c3649303170968806dcc3de8269",
675+
CentralLabelSelector: "rhacs.redhat.com/version-selector=4.6.2",
676+
}
677+
}
678+
679+
func operatorsApplication(operators ...OperatorConfig) argocd.Application {
680+
images := make([]map[string]interface{}, len(operators))
681+
for i, operator := range operators {
682+
images[i] = map[string]interface{}{
683+
"deploymentName": operator.DeploymentName,
684+
"image": operator.Image,
685+
"centralLabelSelector": operator.CentralLabelSelector,
686+
"securedClusterReconcilerEnabled": false,
687+
}
688+
}
689+
690+
return argocd.Application{
691+
ObjectMeta: metav1.ObjectMeta{
692+
Name: "rhacs-operators",
693+
},
694+
Spec: argocd.ApplicationSpec{
695+
IgnoreDifferences: argocd.IgnoreDifferences{
696+
{
697+
Kind: "ServiceAccount",
698+
JSONPointers: []string{"/imagePullSecrets"},
699+
},
700+
},
701+
Destination: argocd.ApplicationDestination{
702+
Namespace: "rhacs",
703+
Server: "https://kubernetes.default.svc",
704+
},
705+
Project: "default",
706+
Source: &argocd.ApplicationSource{
707+
Helm: &argocd.ApplicationSourceHelm{
708+
ValuesObject: &runtime.RawExtension{
709+
Raw: mustJson(map[string]interface{}{
710+
"operator": map[string]interface{}{
711+
"images": images,
712+
},
713+
}),
714+
},
715+
},
716+
Path: "rhacs-operator-legacy",
717+
RepoURL: "https://github.com/stackrox/acscs-manifests",
718+
TargetRevision: "HEAD",
719+
},
720+
SyncPolicy: &argocd.SyncPolicy{
721+
Automated: &argocd.SyncPolicyAutomated{
722+
Prune: true,
723+
SelfHeal: true,
724+
},
725+
},
726+
},
727+
}
728+
}
729+
730+
func crdsApplication() argocd.Application {
731+
return argocd.Application{
732+
ObjectMeta: metav1.ObjectMeta{
733+
Name: "rhacs-crds",
734+
},
735+
Spec: argocd.ApplicationSpec{
736+
Destination: argocd.ApplicationDestination{
737+
Namespace: "rhacs",
738+
Server: "https://kubernetes.default.svc",
739+
},
740+
Project: "default",
741+
Source: &argocd.ApplicationSource{
742+
Directory: &argocd.ApplicationSourceDirectory{
743+
Include: "{platform.stackrox.io_centrals.yaml,platform.stackrox.io_securedclusters.yaml}",
744+
},
745+
Path: "operator/bundle/manifests",
746+
RepoURL: "https://github.com/stackrox/stackrox",
747+
TargetRevision: "4.6.2",
748+
},
749+
SyncPolicy: &argocd.SyncPolicy{
750+
Automated: &argocd.SyncPolicyAutomated{
751+
Prune: true,
752+
SelfHeal: true,
753+
},
754+
SyncOptions: argocd.SyncOptions{"ServerSideApply=true"},
755+
},
756+
},
757+
}
758+
}

internal/dinosaur/pkg/gitops/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gitops
33

44
import (
55
"fmt"
6+
argocd "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
67
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/private"
78
"k8s.io/apimachinery/pkg/util/validation/field"
89
)
@@ -13,7 +14,7 @@ type Config struct {
1314
Centrals CentralsConfig `json:"centrals"`
1415
DataPlaneClusters []DataPlaneClusterConfig `json:"dataPlaneClusters"`
1516
VerticalPodAutoscaling private.VerticalPodAutoscaling `json:"verticalPodAutoscaling"`
16-
Applications []map[string]interface{} `json:"applications"`
17+
Applications []argocd.Application `json:"applications"`
1718
}
1819

1920
// AuthProviderAddition represents tenant's additional auth provider gitops configuration

0 commit comments

Comments
 (0)