Skip to content

Commit be2cf17

Browse files
committed
Create cluster-control-plane-machine-set-operator-tests-ext command for origin e2e
1 parent c2f6cee commit be2cf17

File tree

8 files changed

+187
-90
lines changed

8 files changed

+187
-90
lines changed

.golangci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ issues:
110110
- gosec
111111
- gochecknoglobals
112112
- goerr113
113+
# Exclude some linters from running within the 'test/e2e/' directory.
114+
- path: test/e2e/.*
115+
linters:
116+
- gocyclo
117+
- dupl
118+
- gosec
119+
- gochecknoglobals
120+
- goerr113

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
FROM registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.24-openshift-4.21 AS builder
22
WORKDIR /go/src/github.com/openshift/cluster-control-plane-machine-set-operator
33
COPY . .
4-
RUN make build
4+
RUN make build && \
5+
mkdir -p /tmp/build && \
6+
cp /go/src/github.com/openshift/cluster-control-plane-machine-set-operator/bin/control-plane-machine-set-tests-ext /tmp/build/control-plane-machine-set-tests-ext && \
7+
gzip /tmp/build/control-plane-machine-set-tests-ext
58

69
FROM registry.ci.openshift.org/ocp/4.21:base-rhel9
710
COPY --from=builder /go/src/github.com/openshift/cluster-control-plane-machine-set-operator/bin/manager .
811
COPY --from=builder /go/src/github.com/openshift/cluster-control-plane-machine-set-operator/manifests manifests
12+
COPY --from=builder /tmp/build/control-plane-machine-set-tests-ext.gz .
913

10-
LABEL io.openshift.release.operator true
14+
LABEL io.k8s.display-name="OpenShift Cluster Control Plane Machine Set Operator" \
15+
io.openshift.release.operator=true \
16+
io.openshift.tags="openshift,tests,e2e,e2e-extension"

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,14 @@ verify-%: ## Ensure no diff after running some other target
109109
##@ Build
110110

111111
.PHONY: build
112-
build: generate fmt vet ## Build manager binary.
112+
build: operator tests-ext ## Build all binaries
113+
114+
operator: ## Build main operator binary
113115
go build -o bin/manager ./cmd/control-plane-machine-set-operator
114116

117+
tests-ext: ## Build tests extension binary
118+
go build -o bin/control-plane-machine-set-tests-ext ./cmd/control-plane-machine-set-tests-ext
119+
115120
.PHONY: images
116121
images: ## Create images
117122
$(ENGINE) build -t "$(IMAGE):$(VERSION)" -t "$(IMAGE):$(MUTABLE_TAG)" ./
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2023 Red Hat, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
24+
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
25+
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
26+
"github.com/spf13/cobra"
27+
28+
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
29+
30+
// If using ginkgo, import your tests here.
31+
_ "github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e"
32+
"github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e/framework"
33+
)
34+
35+
func main() {
36+
extensionRegistry := e.NewRegistry()
37+
ext := e.NewExtension("openshift", "payload", "cluster-control-plane-machine-set-operator")
38+
39+
ext.AddSuite(e.Suite{
40+
Name: "cpmso/periodic",
41+
Qualifiers: []string{`!labels.exists(l, l == "Periodic")`},
42+
})
43+
44+
ext.AddSuite(e.Suite{
45+
Name: "cpmso/presubmit",
46+
Qualifiers: []string{`labels.exists(l, l == "PreSubmit") `},
47+
})
48+
49+
specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
50+
if err != nil {
51+
panic(fmt.Sprintf("couldn't build extension test specs from ginkgo: %+v", err.Error()))
52+
}
53+
54+
// Initialize framework before running tests
55+
specs.AddBeforeAll(func() {
56+
if err := framework.InitFramework(); err != nil {
57+
panic(fmt.Sprintf("failed to initialize framework: %v", err))
58+
}
59+
komega.SetClient(framework.GlobalFramework.GetClient())
60+
komega.SetContext(framework.GlobalFramework.GetContext())
61+
})
62+
63+
ext.AddSpecs(specs)
64+
extensionRegistry.Register(ext)
65+
66+
root := &cobra.Command{
67+
Long: "cluster control plane machine set Operator tests extension for OpenShift",
68+
}
69+
70+
root.AddCommand(cmd.DefaultExtensionCommands(extensionRegistry)...)
71+
72+
if err := func() error {
73+
return root.Execute()
74+
}(); err != nil {
75+
os.Exit(1)
76+
}
77+
}

test/e2e/framework/framework.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,34 +130,40 @@ type framework struct {
130130

131131
var _ Framework = &framework{}
132132

133-
// NewFramework initialises a new test framework for the E2E suite.
134-
func NewFramework() (Framework, error) {
133+
// GlobalFramework is a global variable to share state across e2e tests.
134+
var GlobalFramework Framework
135+
136+
// InitFramework initialises a new test framework for the E2E suite.
137+
func InitFramework() error {
135138
sch, err := loadScheme()
136139
if err != nil {
137-
return nil, err
140+
return err
138141
}
139142

140143
client, err := loadClient(sch)
141144
if err != nil {
142-
return nil, err
145+
return err
143146
}
144147

145148
supportLevel, platform, err := getPlatformSupportLevel(client)
146149
if err != nil {
147-
return nil, err
150+
return err
148151
}
149152

150153
logger := textlogger.NewLogger(textlogger.NewConfig())
151154
ctrl.SetLogger(logger)
152155

153-
return &framework{
156+
fw := &framework{
154157
client: client,
155158
logger: logger,
156159
platform: platform,
157160
supportLevel: supportLevel,
158161
scheme: sch,
159162
namespace: MachineAPINamespace,
160-
}, nil
163+
}
164+
GlobalFramework = fw
165+
166+
return nil
161167
}
162168

163169
// NewFrameworkWith initialises a new test framework for the E2E suite
@@ -787,7 +793,7 @@ func nextGCPMachineSize(current string) (string, error) {
787793
// setNextGCPMachineSize returns the new GCP machine size in the series
788794
// according to the family supported (e2, n1, n2).
789795
//
790-
//nolint:cyclop,funlen,gocognit,gocyclo
796+
//nolint:cyclop,funlen,gocognit
791797
func setNextGCPMachineSize(current, family, subfamily, subfamilyflavor string, multiplier float64, multiplier2 int) (string, error) {
792798
switch {
793799
case strings.HasPrefix(subfamily, "custom"):

test/e2e/periodic_test.go renamed to test/e2e/periodic.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ var _ = Describe("ControlPlaneMachineSet Operator", framework.Periodic(), func()
3737

3838
Context("With an active ControlPlaneMachineSet", func() {
3939
BeforeEach(func() {
40-
helpers.EnsureActiveControlPlaneMachineSet(testFramework)
40+
helpers.EnsureActiveControlPlaneMachineSet(framework.GlobalFramework)
4141
})
4242

4343
Context("and the provider spec is changed", func() {
4444
BeforeEach(func() {
45-
helpers.ModifyControlPlaneMachineSetToTriggerRollout(testFramework)
45+
helpers.ModifyControlPlaneMachineSetToTriggerRollout(framework.GlobalFramework)
4646
})
4747

4848
helpers.ItShouldPerformARollingUpdate(&helpers.RollingUpdatePeriodicTestOptions{
49-
TestFramework: testFramework,
49+
TestFramework: framework.GlobalFramework,
5050
})
5151
})
5252

@@ -57,33 +57,33 @@ var _ = Describe("ControlPlaneMachineSet Operator", framework.Periodic(), func()
5757
BeforeEach(func() {
5858
// Check if CPMSMachineNamePrefix gate is enabled, skip otherwise.
5959
// The TechPreview jobs should not skip the test.
60-
featureGateFilter, err := helpers.NewFeatureGateFilter(context.TODO(), testFramework)
60+
featureGateFilter, err := helpers.NewFeatureGateFilter(context.TODO(), framework.GlobalFramework)
6161
if err != nil {
6262
Fail(fmt.Sprintf("failed to get featuregate filter: %v", err))
6363
}
6464
if !featureGateFilter.IsEnabled(string(features.FeatureGateCPMSMachineNamePrefix)) {
6565
Skip(fmt.Sprintf("Skipping test because %q featuregate is not enabled", features.FeatureGateCPMSMachineNamePrefix))
6666
}
6767

68-
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(testFramework, prefix)
68+
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(framework.GlobalFramework, prefix)
6969
}, OncePerOrdered)
7070

7171
Context("and the provider spec of index 1 is not as expected", Ordered, func() {
7272
BeforeAll(func() {
73-
helpers.ModifyMachineProviderSpecToTriggerRollout(testFramework, 1)
73+
helpers.ModifyMachineProviderSpecToTriggerRollout(framework.GlobalFramework, 1)
7474
})
7575

7676
// Machine name should follow prefixed naming convention
77-
helpers.ItShouldRollingUpdateReplaceTheOutdatedMachine(testFramework, 1)
77+
helpers.ItShouldRollingUpdateReplaceTheOutdatedMachine(framework.GlobalFramework, 1)
7878

7979
Context("and again MachineNamePrefix is reset", Ordered, func() {
8080
BeforeAll(func() {
81-
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(testFramework, resetPrefix)
82-
helpers.ModifyMachineProviderSpecToTriggerRollout(testFramework, 1)
81+
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(framework.GlobalFramework, resetPrefix)
82+
helpers.ModifyMachineProviderSpecToTriggerRollout(framework.GlobalFramework, 1)
8383
})
8484

8585
// Machine name should follow general naming convention
86-
helpers.ItShouldRollingUpdateReplaceTheOutdatedMachine(testFramework, 1)
86+
helpers.ItShouldRollingUpdateReplaceTheOutdatedMachine(framework.GlobalFramework, 1)
8787
})
8888
})
8989
})
@@ -92,11 +92,11 @@ var _ = Describe("ControlPlaneMachineSet Operator", framework.Periodic(), func()
9292
var originalStrategy machinev1.ControlPlaneMachineSetStrategyType
9393

9494
BeforeEach(func() {
95-
originalStrategy = helpers.EnsureControlPlaneMachineSetUpdateStrategy(testFramework, machinev1.OnDelete)
95+
originalStrategy = helpers.EnsureControlPlaneMachineSetUpdateStrategy(framework.GlobalFramework, machinev1.OnDelete)
9696
}, OncePerOrdered)
9797

9898
AfterEach(func() {
99-
helpers.EnsureControlPlaneMachineSetUpdateStrategy(testFramework, originalStrategy)
99+
helpers.EnsureControlPlaneMachineSetUpdateStrategy(framework.GlobalFramework, originalStrategy)
100100
}, OncePerOrdered)
101101

102102
Context("and ControlPlaneMachineSet is updated to set MachineNamePrefix [OCPFeatureGate:CPMSMachineNamePrefix]", Ordered, func() {
@@ -106,43 +106,43 @@ var _ = Describe("ControlPlaneMachineSet Operator", framework.Periodic(), func()
106106
BeforeEach(func() {
107107
// Check if CPMSMachineNamePrefix gate is enabled, skip otherwise.
108108
// The TechPreview jobs should not skip the test.
109-
featureGateFilter, err := helpers.NewFeatureGateFilter(context.TODO(), testFramework)
109+
featureGateFilter, err := helpers.NewFeatureGateFilter(context.TODO(), framework.GlobalFramework)
110110
if err != nil {
111111
Fail(fmt.Sprintf("failed to get featuregate filter: %v", err))
112112
}
113113
if !featureGateFilter.IsEnabled(string(features.FeatureGateCPMSMachineNamePrefix)) {
114114
Skip(fmt.Sprintf("Skipping test because %q featuregate is not enabled", features.FeatureGateCPMSMachineNamePrefix))
115115
}
116116

117-
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(testFramework, prefix)
117+
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(framework.GlobalFramework, prefix)
118118
}, OncePerOrdered)
119119

120120
Context("and the provider spec of index 2 is not as expected", Ordered, func() {
121121
var originalProviderSpec machinev1beta1.ProviderSpec
122122

123123
BeforeAll(func() {
124-
originalProviderSpec, _ = helpers.ModifyMachineProviderSpecToTriggerRollout(testFramework, 2)
124+
originalProviderSpec, _ = helpers.ModifyMachineProviderSpecToTriggerRollout(framework.GlobalFramework, 2)
125125
})
126126

127127
AfterAll(func() {
128-
helpers.UpdateControlPlaneMachineProviderSpec(testFramework, 2, originalProviderSpec)
128+
helpers.UpdateControlPlaneMachineProviderSpec(framework.GlobalFramework, 2, originalProviderSpec)
129129
})
130130

131-
helpers.ItShouldNotOnDeleteReplaceTheOutdatedMachine(testFramework, 2)
131+
helpers.ItShouldNotOnDeleteReplaceTheOutdatedMachine(framework.GlobalFramework, 2)
132132

133133
// Machine name should follow prefixed naming convention
134-
helpers.ItShouldOnDeleteReplaceTheOutDatedMachineWhenDeleted(testFramework, 2)
134+
helpers.ItShouldOnDeleteReplaceTheOutDatedMachineWhenDeleted(framework.GlobalFramework, 2)
135135

136136
Context("and again MachineNamePrefix is reset", Ordered, func() {
137137
BeforeAll(func() {
138-
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(testFramework, resetPrefix)
139-
helpers.ModifyMachineProviderSpecToTriggerRollout(testFramework, 2)
138+
helpers.UpdateControlPlaneMachineSetMachineNamePrefix(framework.GlobalFramework, resetPrefix)
139+
helpers.ModifyMachineProviderSpecToTriggerRollout(framework.GlobalFramework, 2)
140140
})
141141

142-
helpers.ItShouldNotOnDeleteReplaceTheOutdatedMachine(testFramework, 2)
142+
helpers.ItShouldNotOnDeleteReplaceTheOutdatedMachine(framework.GlobalFramework, 2)
143143

144144
// Machine name should follow general naming convention
145-
helpers.ItShouldOnDeleteReplaceTheOutDatedMachineWhenDeleted(testFramework, 2)
145+
helpers.ItShouldOnDeleteReplaceTheOutDatedMachineWhenDeleted(framework.GlobalFramework, 2)
146146
})
147147
})
148148
})

0 commit comments

Comments
 (0)