Skip to content

Commit 273a2a8

Browse files
committed
test: patch existing CSV for a hotfix
This is a test for the hotfix scenario, where an existing CSV is patched directly to update the deployment spec. Ref: #1774
1 parent 591aace commit 273a2a8

File tree

3 files changed

+147
-10
lines changed

3 files changed

+147
-10
lines changed

Makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ GO := GO111MODULE=on GOFLAGS="$(MOD_FLAGS)" go
2929
GINKGO := $(GO) run github.com/onsi/ginkgo/ginkgo
3030
BINDATA := $(GO) run github.com/go-bindata/go-bindata/v3/go-bindata
3131

32-
# ART builds are performed in dist-git, with content (but not commits) copied
32+
# ART builds are performed in dist-git, with content (but not commits) copied
3333
# from the source repo. Thus at build time if your code is inspecting the local
34-
# git repo it is getting unrelated commits and tags from the dist-git repo,
34+
# git repo it is getting unrelated commits and tags from the dist-git repo,
3535
# not the source repo.
36-
# For ART image builds, SOURCE_GIT_COMMIT, SOURCE_GIT_TAG, SOURCE_DATE_EPOCH
37-
# variables are inserted in Dockerfile to enable recovering the original git
36+
# For ART image builds, SOURCE_GIT_COMMIT, SOURCE_GIT_TAG, SOURCE_DATE_EPOCH
37+
# variables are inserted in Dockerfile to enable recovering the original git
3838
# metadata at build time.
3939
GIT_COMMIT := $(if $(SOURCE_GIT_COMMIT),$(SOURCE_GIT_COMMIT),$(shell git rev-parse HEAD))
4040

@@ -87,15 +87,15 @@ build-coverage: build_cmd=test -c -covermode=count -coverpkg ./pkg/controller/..
8787
build-coverage: clean $(CMDS)
8888

8989
build-linux: build_cmd=build
90-
build-linux: arch_flags=GOOS=linux GOARCH=386
90+
build-linux: arch_flags=GOOS=linux GOARCH=amd64
9191
build-linux: clean $(CMDS)
9292

9393
build-wait: clean bin/wait
9494

9595
bin/wait: FORCE
96-
GOOS=linux GOARCH=386 go build $(MOD_FLAGS) -o $@ $(PKG)/test/e2e/wait
96+
GOOS=linux GOARCH=amd64 go build $(MOD_FLAGS) -o $@ $(PKG)/test/e2e/wait
9797

98-
build-util-linux: arch_flags=GOOS=linux GOARCH=386
98+
build-util-linux: arch_flags=GOOS=linux GOARCH=amd64
9999
build-util-linux: build-util
100100

101101
build-util: bin/cpb
@@ -140,7 +140,7 @@ FORCE:
140140
# main entry point for running end to end tests. used by .github/workflows/e2e-tests.yml See test/e2e/README.md for details
141141
.PHONY: e2e-local
142142
e2e-local: bin/e2e-local.test test/e2e-local.image.tar
143-
$(GINKGO) -nodes $(or $(NODES),1) -flakeAttempts 3 -randomizeAllSpecs $(if $(TEST),-focus '$(TEST)') -v -timeout 90m $< -- -namespace=operators -olmNamespace=operator-lifecycle-manager -dummyImage=bitnami/nginx:latest -kind.images=../test/e2e-local.image.tar
143+
$(GINKGO) -nodes $(or $(NODES),1) -flakeAttempts 1 -randomizeAllSpecs $(if $(TEST),-focus '$(TEST)') -v -timeout 90m $< -- -namespace=operators -olmNamespace=operator-lifecycle-manager -dummyImage=bitnami/nginx:latest -kind.images=../test/e2e-local.image.tar -toolsBin=$(TOOLS_BIN)
144144

145145
# this target updates the zz_chart.go file with files found in deploy/chart
146146
# this will always fire since it has been marked as phony
@@ -154,7 +154,7 @@ bin/e2e-local.test: FORCE test/e2e/assets/chart/zz_chart.go
154154

155155
# set go env and other vars, ensure that the dockerfile exists, and then build wait, cpb, and other command binaries and finally the kind image archive
156156
test/e2e-local.image.tar: export GOOS=linux
157-
test/e2e-local.image.tar: export GOARCH=386
157+
test/e2e-local.image.tar: export GOARCH=amd64
158158
test/e2e-local.image.tar: build_cmd=build
159159
test/e2e-local.image.tar: e2e.Dockerfile bin/wait bin/cpb $(CMDS)
160160
docker build -t quay.io/operator-framework/olm:local -f $< bin

test/e2e/csv_e2e_test.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,144 @@ var _ = Describe("ClusterServiceVersion", func() {
29152915
err = waitForDeploymentToDelete(c, strategy.DeploymentSpecs[0].Name)
29162916
Expect(err).ShouldNot(HaveOccurred())
29172917
})
2918+
It("update deployment spec in an existing CSV for a hotfix", func() {
29182919

2920+
c := newKubeClient()
2921+
crc := newCRClient()
2922+
2923+
// Create dependency first (CRD)
2924+
crdPlural := genName("ins")
2925+
crdName := crdPlural + ".cluster.com"
2926+
cleanupCRD, err := createCRD(c, apiextensions.CustomResourceDefinition{
2927+
ObjectMeta: metav1.ObjectMeta{
2928+
Name: crdName,
2929+
},
2930+
Spec: apiextensions.CustomResourceDefinitionSpec{
2931+
Group: "cluster.com",
2932+
Version: "v1alpha1",
2933+
Names: apiextensions.CustomResourceDefinitionNames{
2934+
Plural: crdPlural,
2935+
Singular: crdPlural,
2936+
Kind: crdPlural,
2937+
ListKind: "list" + crdPlural,
2938+
},
2939+
Scope: "Namespaced",
2940+
},
2941+
})
2942+
defer cleanupCRD()
2943+
Expect(err).ShouldNot(HaveOccurred())
2944+
2945+
// Create "current" CSV
2946+
nginxName := genName("nginx-")
2947+
strategy := v1alpha1.StrategyDetailsDeployment{
2948+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
2949+
{
2950+
Name: genName("dep-"),
2951+
Spec: newNginxDeployment(nginxName),
2952+
},
2953+
},
2954+
}
2955+
2956+
csv := v1alpha1.ClusterServiceVersion{
2957+
TypeMeta: metav1.TypeMeta{
2958+
Kind: v1alpha1.ClusterServiceVersionKind,
2959+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
2960+
},
2961+
ObjectMeta: metav1.ObjectMeta{
2962+
Name: genName("csv"),
2963+
},
2964+
Spec: v1alpha1.ClusterServiceVersionSpec{
2965+
MinKubeVersion: "0.0.0",
2966+
InstallModes: []v1alpha1.InstallMode{
2967+
{
2968+
Type: v1alpha1.InstallModeTypeOwnNamespace,
2969+
Supported: true,
2970+
},
2971+
{
2972+
Type: v1alpha1.InstallModeTypeSingleNamespace,
2973+
Supported: true,
2974+
},
2975+
{
2976+
Type: v1alpha1.InstallModeTypeMultiNamespace,
2977+
Supported: true,
2978+
},
2979+
{
2980+
Type: v1alpha1.InstallModeTypeAllNamespaces,
2981+
Supported: true,
2982+
},
2983+
},
2984+
InstallStrategy: v1alpha1.NamedInstallStrategy{
2985+
StrategyName: v1alpha1.InstallStrategyNameDeployment,
2986+
StrategySpec: strategy,
2987+
},
2988+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
2989+
Owned: []v1alpha1.CRDDescription{
2990+
{
2991+
Name: crdName,
2992+
Version: "v1alpha1",
2993+
Kind: crdPlural,
2994+
DisplayName: crdName,
2995+
Description: "In the cluster",
2996+
},
2997+
},
2998+
},
2999+
},
3000+
}
3001+
3002+
cleanupCSV, err := createCSV(c, crc, csv, testNamespace, true, false)
3003+
Expect(err).ShouldNot(HaveOccurred())
3004+
defer cleanupCSV()
3005+
3006+
// Wait for current CSV to succeed
3007+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3008+
Expect(err).ShouldNot(HaveOccurred())
3009+
3010+
// Should have created deployment
3011+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
3012+
Expect(err).ShouldNot(HaveOccurred())
3013+
Expect(dep).ShouldNot(BeNil())
3014+
3015+
// Create "updated" CSV
3016+
strategyNew := v1alpha1.StrategyDetailsDeployment{
3017+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
3018+
{
3019+
// Same name
3020+
Name: strategy.DeploymentSpecs[0].Name,
3021+
// Different spec
3022+
Spec: newNginxDeployment(nginxName),
3023+
},
3024+
},
3025+
}
3026+
3027+
// Fetch the current csv
3028+
fetchedCSV, err := fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
3029+
Expect(err).ShouldNot(HaveOccurred())
3030+
3031+
// Update csv with modified deployment spec
3032+
fetchedCSV.Spec.InstallStrategy.StrategySpec = strategyNew
3033+
3034+
Eventually(func() error {
3035+
// Update the current csv
3036+
_, err = crc.OperatorsV1alpha1().ClusterServiceVersions(testNamespace).Update(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
3037+
return err
3038+
}).Should(Succeed())
3039+
3040+
// Wait for updated CSV to succeed
3041+
_, err = fetchCSV(crc, csv.Name, testNamespace, func(csv *v1alpha1.ClusterServiceVersion) bool {
3042+
3043+
// Should have updated existing deployment
3044+
depUpdated, err := c.GetDeployment(testNamespace, strategyNew.DeploymentSpecs[0].Name)
3045+
Expect(err).ShouldNot(HaveOccurred())
3046+
Expect(depUpdated).ShouldNot(BeNil())
3047+
// container name has been updated and differs from initial CSV spec and updated CSV spec
3048+
Expect(depUpdated.Spec.Template.Spec.Containers[0].Name).ShouldNot(Equal(strategyNew.DeploymentSpecs[0].Spec.Template.Spec.Containers[0].Name))
3049+
3050+
// Check for success
3051+
return csvSucceededChecker(csv)
3052+
})
3053+
Expect(err).ShouldNot(HaveOccurred())
3054+
3055+
})
29193056
It("emits CSV requirement events", func() {
29203057

29213058
csv := &v1alpha1.ClusterServiceVersion{

test/e2e/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848

4949
const (
5050
pollInterval = 1 * time.Second
51-
pollDuration = 5 * time.Minute
51+
pollDuration = 10 * time.Minute
5252

5353
olmConfigMap = "olm-operators" // No-longer used, how long do we keep this around?
5454

0 commit comments

Comments
 (0)