Skip to content

Commit ed7cf0d

Browse files
Merge pull request #279 from perdasilva/ds_sync
sync update staging directory 04-07
2 parents 491ea01 + efa6815 commit ed7cf0d

File tree

14 files changed

+313
-24
lines changed

14 files changed

+313
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,5 @@ staging/*/vendor
466466
values-crc-e2e.yaml
467467
scripts/**/*.crc.e2e.patch.yaml
468468

469+
# downstream sync sha files
470+
*.cherrypick

scripts/generate_crds_manifests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/usr/bin/env bash
22

33
set -o errexit
44
set -o nounset
@@ -43,11 +43,12 @@ sed -i "s/^[Vv]ersion:.*\$/version: ${ver}/" "${chartdir}/Chart.yaml"
4343
# CRC_E2E_VALUES contains the path to the values file used for running olm on crc locally
4444
# this file is generated in scripts/crc-deploy.sh
4545
CRC_E2E_VALUES=${CRC_E2E_VALUES-""}
46+
CRC_E2E=("")
4647
if ! [ "${CRC_E2E_VALUES}" = "" ]; then
4748
CRC_E2E=(-f "${tmpdir}/${CRC_E2E_VALUES}")
4849
fi
4950

50-
${HELM} template -n olm -f "${tmpdir}/values.yaml" "${CRC_E2E[@]}" --include-crds --output-dir "${chartdir}" "${chartdir}"
51+
${HELM} template -n olm -f "${tmpdir}/values.yaml" ${CRC_E2E[@]} --include-crds --output-dir "${chartdir}" "${chartdir}"
5152
cp -R "${chartdir}"/olm/{templates,crds}/. "./manifests"
5253

5354
add_ibm_managed_cloud_annotations() {

scripts/sync_get_candidates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -o errexit
44
set -o pipefail

scripts/sync_pop_candidate.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
#!/bin/bash
3-
1+
#!/usr/bin/env bash
42

53
cph=$(git rev-list -n 1 CHERRY_PICK_HEAD 2> /dev/null)
64

staging/operator-lifecycle-manager/.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/setup-go@v2
2020
with:
2121
go-version: '~1.17'
22-
- run: make e2e-local E2E_TEST_CHUNK=${{ matrix.parallel-id }} E2E_TEST_NUM_CHUNKS=${{ strategy.job-total }} E2E_NODES=2 ARTIFACTS_DIR=./artifacts/ SKIP='\[FLAKE\]'
22+
- run: make e2e-local E2E_TEST_CHUNK=${{ matrix.parallel-id }} E2E_TEST_NUM_CHUNKS=${{ strategy.job-total }} E2E_NODES=2 ARTIFACT_DIR=./artifacts/ SKIP='\[FLAKE\]'
2323
- name: Archive Test Artifacts # test results, failed or not, are always uploaded.
2424
if: ${{ always() }}
2525
uses: actions/upload-artifact@v2

staging/operator-lifecycle-manager/.github/workflows/flaky-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/setup-go@v2
1616
with:
1717
go-version: '~1.17'
18-
- run: make e2e-local E2E_NODES=1 TEST='\[FLAKE\]' ARTIFACTS_DIR=./artifacts/
18+
- run: make e2e-local E2E_NODES=1 TEST='\[FLAKE\]' ARTIFACT_DIR=./artifacts/
1919
- name: Archive Test Artifacts # test results, failed or not, are always uploaded.
2020
if: ${{ always() }}
2121
uses: actions/upload-artifact@v2

staging/operator-lifecycle-manager/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,5 @@ apiserver.key
455455

456456
!vendor/**
457457
test/e2e-local.image.tar
458-
458+
test/e2e/.kube
459459
dist/

staging/operator-lifecycle-manager/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,10 @@ E2E_TEST_NS ?= operators
139139
e2e:
140140
$(GINKGO) $(E2E_OPTS) $(or $(run), ./test/e2e) $< -- -namespace=$(E2E_TEST_NS) -olmNamespace=$(E2E_INSTALL_NS) -dummyImage=bitnami/nginx:latest $(or $(extra_args), -kubeconfig=${KUBECONFIG})
141141

142-
143142
# See workflows/e2e-tests.yml See test/e2e/README.md for details.
144143
.PHONY: e2e-local
145144
e2e-local: BUILD_TAGS="json1 experimental_metrics"
146-
e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar -test-data-dir=../test/e2e/testdata
145+
e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar -test-data-dir=../test/e2e/testdata -gather-artifacts-script-path=../test/e2e/collect-ci-artifacts.sh
147146
e2e-local: run=bin/e2e-local.test
148147
e2e-local: bin/e2e-local.test test/e2e-local.image.tar
149148
e2e-local: e2e

staging/operator-lifecycle-manager/test/e2e/ctx/ctx.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import (
77
"path/filepath"
88
"strings"
99

10-
g "github.com/onsi/ginkgo"
10+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/util"
11+
appsv1 "k8s.io/api/apps/v1"
1112
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
13+
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
14+
15+
g "github.com/onsi/ginkgo"
1216
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1317
"k8s.io/apimachinery/pkg/runtime"
1418
"k8s.io/client-go/dynamic"
@@ -35,10 +39,12 @@ type TestContext struct {
3539
operatorClient versioned.Interface
3640
dynamicClient dynamic.Interface
3741
packageClient pversioned.Interface
42+
e2eClient *util.E2EKubeClient
3843
ssaClient *controllerclient.ServerSideApplier
3944

40-
kubeconfigPath string
41-
artifactsDir string
45+
kubeconfigPath string
46+
artifactsDir string
47+
artifactsScriptPath string
4248

4349
scheme *runtime.Scheme
4450

@@ -93,9 +99,20 @@ func (ctx TestContext) SSAClient() *controllerclient.ServerSideApplier {
9399
return ctx.ssaClient
94100
}
95101

102+
func (ctx TestContext) E2EClient() *util.E2EKubeClient {
103+
return ctx.e2eClient
104+
}
105+
106+
func (ctx TestContext) NewE2EClientSession() {
107+
if ctx.e2eClient != nil {
108+
_ = ctx.e2eClient.Reset()
109+
}
110+
ctx.e2eClient = util.NewK8sResourceManager(ctx.Client())
111+
}
112+
96113
func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
97114
if ctx.artifactsDir == "" {
98-
ctx.Logf("$ARTIFACTS_DIR is unset -- not collecting failed test case logs")
115+
ctx.Logf("$ARTIFACT_DIR is unset -- not collecting failed test case logs")
99116
return nil
100117
}
101118
ctx.Logf("collecting logs in the %s artifacts directory", ctx.artifactsDir)
@@ -116,8 +133,7 @@ func (ctx TestContext) DumpNamespaceArtifacts(namespace string) error {
116133
"KUBECONFIG=" + kubeconfigPath,
117134
}
118135

119-
// compiled test binary running e2e tests is run from the root ./bin directory
120-
cmd := exec.Command("../test/e2e/collect-ci-artifacts.sh")
136+
cmd := exec.Command(ctx.artifactsScriptPath)
121137
cmd.Env = append(cmd.Env, envvars...)
122138
cmd.Stdout = os.Stdout
123139
cmd.Stderr = os.Stderr
@@ -137,6 +153,17 @@ func setDerivedFields(ctx *TestContext) error {
137153
return fmt.Errorf("nil RESTClient")
138154
}
139155

156+
if ctx.artifactsDir == "" {
157+
if artifactsDir := os.Getenv("ARTIFACT_DIR"); artifactsDir != "" {
158+
ctx.artifactsDir = artifactsDir
159+
}
160+
}
161+
if ctx.artifactsScriptPath == "" {
162+
if scriptPath := os.Getenv("E2E_ARTIFACT_SCRIPT"); scriptPath != "" {
163+
ctx.artifactsScriptPath = scriptPath
164+
}
165+
}
166+
140167
kubeClient, err := operatorclient.NewClientFromRestConfig(ctx.restConfig)
141168
if err != nil {
142169
return err
@@ -163,12 +190,14 @@ func setDerivedFields(ctx *TestContext) error {
163190

164191
ctx.scheme = runtime.NewScheme()
165192
localSchemeBuilder := runtime.NewSchemeBuilder(
193+
apiextensions.AddToScheme,
166194
kscheme.AddToScheme,
167195
operatorsv1alpha1.AddToScheme,
168196
operatorsv1.AddToScheme,
169197
operatorsv2.AddToScheme,
170198
apiextensionsv1.AddToScheme,
171-
apiextensions.AddToScheme,
199+
appsv1.AddToScheme,
200+
apiregistrationv1.AddToScheme,
172201
)
173202
if err := localSchemeBuilder.AddToScheme(ctx.scheme); err != nil {
174203
return err
@@ -181,6 +210,7 @@ func setDerivedFields(ctx *TestContext) error {
181210
return err
182211
}
183212
ctx.client = client
213+
ctx.e2eClient = util.NewK8sResourceManager(client)
184214

185215
ctx.ssaClient, err = controllerclient.NewForConfig(ctx.restConfig, ctx.scheme, "test.olm.registry")
186216
if err != nil {

staging/operator-lifecycle-manager/test/e2e/ctx/provisioner_kind.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build kind
12
// +build kind
23

34
package ctx
@@ -135,10 +136,6 @@ func Provision(ctx *TestContext) (func(), error) {
135136
return nil, fmt.Errorf("error loading kubeconfig: %s", err.Error())
136137
}
137138
ctx.restConfig = restConfig
138-
139-
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
140-
ctx.artifactsDir = artifactsDir
141-
}
142139
ctx.kubeconfigPath = kubeconfigPath
143140

144141
var once sync.Once

staging/operator-lifecycle-manager/test/e2e/e2e_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ var (
4242
"dummy image to treat as an operator in tests",
4343
)
4444

45+
collectArtifactsScriptPath = flag.String(
46+
"gather-artifacts-script-path",
47+
"./collect-ci-artifacts.sh",
48+
"configures the relative/absolute path to the script resposible for collecting CI artifacts",
49+
)
50+
4551
testdataPath = flag.String(
4652
"test-data-dir",
4753
"./testdata",
@@ -62,8 +68,8 @@ func TestEndToEnd(t *testing.T) {
6268
SetDefaultConsistentlyDuration(30 * time.Second)
6369
SetDefaultConsistentlyPollingInterval(1 * time.Second)
6470

65-
// always configure a junit report when ARTIFACTS_DIR has been set
66-
if artifactsDir := os.Getenv("ARTIFACTS_DIR"); artifactsDir != "" {
71+
// always configure a junit report when ARTIFACT_DIR has been set
72+
if artifactsDir := os.Getenv("ARTIFACT_DIR"); artifactsDir != "" {
6773
junitReporter := reporters.NewJUnitReporter(path.Join(artifactsDir, junitDir, fmt.Sprintf("junit_e2e_%02d.xml", config.GinkgoConfig.ParallelNode)))
6874
RunSpecsWithDefaultAndCustomReporters(t, "End-to-end", []Reporter{junitReporter})
6975
} else if junitDir := os.Getenv("JUNIT_DIRECTORY"); junitDir != "" { // Downstream-only legacy requirement
@@ -82,6 +88,9 @@ var _ = BeforeSuite(func() {
8288
// This flag can be deprecated in favor of the kubeconfig provisioner:
8389
os.Setenv("KUBECONFIG", *kubeConfigPath)
8490
}
91+
if collectArtifactsScriptPath != nil && *collectArtifactsScriptPath != "" {
92+
os.Setenv("E2E_ARTIFACT_SCRIPT", *collectArtifactsScriptPath)
93+
}
8594

8695
testNamespace = *namespace
8796
operatorNamespace = *olmNamespace
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/util"
9+
corev1 "k8s.io/api/core/v1"
10+
k8serror "k8s.io/apimachinery/pkg/api/errors"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
"sigs.k8s.io/controller-runtime/pkg/client"
13+
14+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
15+
)
16+
17+
var _ = Describe("ResourceManager", func() {
18+
19+
var generatedNamespace corev1.Namespace
20+
21+
BeforeEach(func() {
22+
ctx.Ctx().NewE2EClientSession()
23+
generatedNamespace = SetupGeneratedTestNamespace(genName("resource-manager-e2e-"))
24+
})
25+
26+
AfterEach(func() {
27+
TeardownNamespace(generatedNamespace.GetName())
28+
Expect(ctx.Ctx().E2EClient().Reset()).To(Succeed())
29+
})
30+
31+
It("should tag resources created with it", func() {
32+
// Create a namespace
33+
ns := &corev1.Namespace{
34+
ObjectMeta: metav1.ObjectMeta{
35+
Name: genName("test-"),
36+
},
37+
}
38+
Expect(ctx.Ctx().E2EClient().Create(context.TODO(), ns)).To(Succeed())
39+
40+
// Get namespace
41+
Expect(ctx.Ctx().E2EClient().Get(context.TODO(), client.ObjectKeyFromObject(ns), ns)).To(Succeed())
42+
Expect(ns.GetAnnotations()).NotTo(BeEmpty())
43+
Expect(ns.GetAnnotations()[util.E2ETestNameTag]).To(Equal("ResourceManager should tag resources created with it"))
44+
})
45+
46+
It("should delete resources on reset", func() {
47+
// Create a namespace
48+
ns := &corev1.Namespace{
49+
ObjectMeta: metav1.ObjectMeta{
50+
Name: genName("test-"),
51+
},
52+
}
53+
Expect(ctx.Ctx().E2EClient().Create(context.TODO(), ns)).To(Succeed())
54+
55+
// Add a config map
56+
configMap := &corev1.ConfigMap{
57+
ObjectMeta: metav1.ObjectMeta{
58+
Name: genName("configmap-"),
59+
60+
// creating the configmap in the generated (spec) namespace
61+
// so if the namespace (ns, above) gets deleted on reset it won't take the config map with it
62+
Namespace: generatedNamespace.GetName(),
63+
},
64+
}
65+
Expect(ctx.Ctx().E2EClient().Create(context.TODO(), configMap))
66+
67+
// Reset the client
68+
Expect(ctx.Ctx().E2EClient().Reset()).To(Succeed())
69+
70+
// And just like that resources should be gone
71+
Eventually(func() error {
72+
return ctx.Ctx().E2EClient().Get(context.TODO(), client.ObjectKeyFromObject(configMap), configMap)
73+
}).Should(WithTransform(k8serror.IsNotFound, BeTrue()))
74+
Eventually(func() error {
75+
return ctx.Ctx().E2EClient().Get(context.TODO(), client.ObjectKeyFromObject(ns), ns)
76+
}).Should(WithTransform(k8serror.IsNotFound, BeTrue()))
77+
})
78+
})
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package util
2+
3+
import (
4+
"context"
5+
6+
"github.com/onsi/ginkgo"
7+
k8serror "k8s.io/apimachinery/pkg/api/errors"
8+
k8scontrollerclient "sigs.k8s.io/controller-runtime/pkg/client"
9+
)
10+
11+
const (
12+
E2ETestNameTag = "e2e.testName"
13+
)
14+
15+
type E2EKubeClient struct {
16+
k8scontrollerclient.Client
17+
createdResources *ResourceQueue
18+
}
19+
20+
func NewK8sResourceManager(client k8scontrollerclient.Client) *E2EKubeClient {
21+
return &E2EKubeClient{
22+
Client: client,
23+
createdResources: NewResourceQueue(),
24+
}
25+
}
26+
27+
func (m *E2EKubeClient) Create(context context.Context, obj k8scontrollerclient.Object, options ...k8scontrollerclient.CreateOption) error {
28+
m.annotateTestResource(obj)
29+
if err := m.Client.Create(context, obj, options...); err != nil {
30+
return err
31+
}
32+
m.createdResources.EnqueueIgnoreExisting(obj)
33+
return nil
34+
}
35+
36+
func (m *E2EKubeClient) Update(context context.Context, obj k8scontrollerclient.Object, options ...k8scontrollerclient.UpdateOption) error {
37+
m.annotateTestResource(obj)
38+
if err := m.Client.Update(context, obj, options...); err != nil {
39+
return err
40+
}
41+
m.createdResources.EnqueueIgnoreExisting(obj)
42+
return nil
43+
}
44+
45+
func (m *E2EKubeClient) Delete(context context.Context, obj k8scontrollerclient.Object, options ...k8scontrollerclient.DeleteOption) error {
46+
if err := m.Client.Delete(context, obj, options...); err != nil {
47+
return err
48+
}
49+
m.createdResources.RemoveIgnoreNotFound(obj)
50+
return nil
51+
}
52+
53+
func (m *E2EKubeClient) Reset() error {
54+
for {
55+
obj, ok := m.createdResources.DequeueTail()
56+
57+
if !ok {
58+
break
59+
}
60+
61+
if err := m.Delete(context.TODO(), obj); err != nil && !k8serror.IsNotFound(err) {
62+
return err
63+
}
64+
}
65+
return nil
66+
}
67+
68+
func (m *E2EKubeClient) annotateTestResource(obj k8scontrollerclient.Object) {
69+
annotations := obj.GetAnnotations()
70+
if annotations == nil {
71+
annotations = make(map[string]string)
72+
}
73+
annotations[E2ETestNameTag] = ginkgo.CurrentGinkgoTestDescription().FullTestText
74+
obj.SetAnnotations(annotations)
75+
}

0 commit comments

Comments
 (0)