Skip to content

Commit 05fcc63

Browse files
committed
Fix deprecated installPlan step resource test
Signed-off-by: Alexander Greene <[email protected]>
1 parent ca5d02f commit 05fcc63

File tree

8 files changed

+145
-61
lines changed

8 files changed

+145
-61
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ e2e:
146146

147147
# See workflows/e2e-tests.yml See test/e2e/README.md for details.
148148
.PHONY: e2e-local
149-
e2e-local: BUILD_TAGS="json1 experimental_metrics"
149+
e2e-local: BUILD_TAGS="json1 e2e experimental_metrics"
150150
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
151151
e2e-local: run=bin/e2e-local.test
152152
e2e-local: bin/e2e-local.test test/e2e-local.image.tar

Diff for: pkg/controller/operators/catalog/operator.go

-30
Original file line numberDiff line numberDiff line change
@@ -2532,33 +2532,3 @@ func (o *Operator) apiresourceFromGVK(gvk schema.GroupVersionKind) (metav1.APIRe
25322532
logger.Info("couldn't find GVK in api discovery")
25332533
return metav1.APIResource{}, olmerrors.GroupVersionKindNotFoundError{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind}
25342534
}
2535-
2536-
const (
2537-
PrometheusRuleKind = "PrometheusRule"
2538-
ServiceMonitorKind = "ServiceMonitor"
2539-
PodDisruptionBudgetKind = "PodDisruptionBudget"
2540-
PriorityClassKind = "PriorityClass"
2541-
VerticalPodAutoscalerKind = "VerticalPodAutoscaler"
2542-
ConsoleYAMLSampleKind = "ConsoleYAMLSample"
2543-
ConsoleQuickStartKind = "ConsoleQuickStart"
2544-
ConsoleCLIDownloadKind = "ConsoleCLIDownload"
2545-
ConsoleLinkKind = "ConsoleLink"
2546-
)
2547-
2548-
var supportedKinds = map[string]struct{}{
2549-
PrometheusRuleKind: {},
2550-
ServiceMonitorKind: {},
2551-
PodDisruptionBudgetKind: {},
2552-
PriorityClassKind: {},
2553-
VerticalPodAutoscalerKind: {},
2554-
ConsoleYAMLSampleKind: {},
2555-
ConsoleQuickStartKind: {},
2556-
ConsoleCLIDownloadKind: {},
2557-
ConsoleLinkKind: {},
2558-
}
2559-
2560-
// isSupported returns true if OLM supports this type of CustomResource.
2561-
func isSupported(kind string) bool {
2562-
_, ok := supportedKinds[kind]
2563-
return ok
2564-
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package catalog
2+
3+
const (
4+
PrometheusRuleKind = "PrometheusRule"
5+
ServiceMonitorKind = "ServiceMonitor"
6+
PodDisruptionBudgetKind = "PodDisruptionBudget"
7+
PriorityClassKind = "PriorityClass"
8+
VerticalPodAutoscalerKind = "VerticalPodAutoscaler"
9+
ConsoleYAMLSampleKind = "ConsoleYAMLSample"
10+
ConsoleQuickStartKind = "ConsoleQuickStart"
11+
ConsoleCLIDownloadKind = "ConsoleCLIDownload"
12+
ConsoleLinkKind = "ConsoleLink"
13+
)
14+
15+
var supportedKinds = map[string]struct{}{
16+
PrometheusRuleKind: {},
17+
ServiceMonitorKind: {},
18+
PodDisruptionBudgetKind: {},
19+
PriorityClassKind: {},
20+
VerticalPodAutoscalerKind: {},
21+
ConsoleYAMLSampleKind: {},
22+
ConsoleQuickStartKind: {},
23+
ConsoleCLIDownloadKind: {},
24+
ConsoleLinkKind: {},
25+
}
26+
27+
// isSupported returns true if OLM supports this type of CustomResource.
28+
func isSupported(kind string) bool {
29+
_, ok := supportedKinds[kind]
30+
return ok
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build e2e
2+
3+
package catalog
4+
5+
const (
6+
DeprecatedKind = "Deprecated"
7+
)
8+
9+
func init() {
10+
supportedKinds[DeprecatedKind] = struct{}{}
11+
}

Diff for: test/e2e/installplan_e2e_test.go

+27-30
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
appsv1 "k8s.io/api/apps/v1"
2121
authorizationv1 "k8s.io/api/authorization/v1"
2222
corev1 "k8s.io/api/core/v1"
23-
policyv1beta1 "k8s.io/api/policy/v1beta1"
2423
rbacv1 "k8s.io/api/rbac/v1"
2524
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
2625
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -48,6 +47,7 @@ import (
4847
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
4948
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
5049
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/ctx"
50+
"github.com/operator-framework/operator-lifecycle-manager/test/e2e/util"
5151
)
5252

5353
var _ = Describe("Install Plan", func() {
@@ -76,11 +76,11 @@ var _ = Describe("Install Plan", func() {
7676

7777
When("an InstallPlan step contains a deprecated resource version", func() {
7878
var (
79-
csv operatorsv1alpha1.ClusterServiceVersion
80-
plan operatorsv1alpha1.InstallPlan
81-
pdb policyv1beta1.PodDisruptionBudget
82-
manifest string
83-
counter float64
79+
csv operatorsv1alpha1.ClusterServiceVersion
80+
plan operatorsv1alpha1.InstallPlan
81+
deprecated client.Object
82+
manifest string
83+
counter float64
8484
)
8585

8686
BeforeEach(func() {
@@ -90,13 +90,8 @@ var _ = Describe("Install Plan", func() {
9090
v, err := dc.ServerVersion()
9191
Expect(err).ToNot(HaveOccurred())
9292

93-
if minor, err := strconv.Atoi(v.Minor); err == nil && minor < 21 {
94-
// This is a tactical can-kick with
95-
// the expectation that the
96-
// event-emitting behavior being
97-
// tested in this context will have
98-
// moved by the time 1.25 arrives.
99-
Skip("hack: test is dependent on 1.21+ behavior")
93+
if minor, err := strconv.Atoi(v.Minor); err == nil && minor < 16 {
94+
Skip("test is dependent on CRD v1 introduced at 1.16")
10095
}
10196
})
10297

@@ -107,26 +102,21 @@ var _ = Describe("Install Plan", func() {
107102
counter = metric.Value
108103
}
109104
}
105+
deprecatedCRD, err := util.DecodeFile("./testdata/deprecated-crd/deprecated.crd.yaml", &apiextensionsv1.CustomResourceDefinition{})
106+
Expect(err).NotTo(HaveOccurred())
107+
108+
Expect(ctx.Ctx().Client().Create(context.Background(), deprecatedCRD)).To(Succeed())
110109

111110
csv = newCSV(genName("test-csv-"), ns.GetName(), "", semver.Version{}, nil, nil, nil)
112111
Expect(ctx.Ctx().Client().Create(context.Background(), &csv)).To(Succeed())
113112

114-
pdb = policyv1beta1.PodDisruptionBudget{
115-
ObjectMeta: metav1.ObjectMeta{
116-
Name: genName("test-pdb-"),
117-
},
118-
TypeMeta: metav1.TypeMeta{
119-
Kind: "PodDisruptionBudget",
120-
APIVersion: policyv1beta1.SchemeGroupVersion.String(),
121-
},
122-
Spec: policyv1beta1.PodDisruptionBudgetSpec{},
123-
}
113+
deprecated, err = util.DecodeFile("./testdata/deprecated-crd/deprecated.cr.yaml", &unstructured.Unstructured{}, util.WithNamespace(ns.GetName()))
114+
Expect(err).NotTo(HaveOccurred())
124115

125116
scheme := runtime.NewScheme()
126-
Expect(policyv1beta1.AddToScheme(scheme)).To(Succeed())
127117
{
128118
var b bytes.Buffer
129-
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&pdb, &b)).To(Succeed())
119+
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(deprecated, &b)).To(Succeed())
130120
manifest = b.String()
131121
}
132122

@@ -150,9 +140,9 @@ var _ = Describe("Install Plan", func() {
150140
Resolving: csv.GetName(),
151141
Status: operatorsv1alpha1.StepStatusUnknown,
152142
Resource: operatorsv1alpha1.StepResource{
153-
Name: pdb.GetName(),
154-
Version: pdb.APIVersion,
155-
Kind: pdb.Kind,
143+
Name: deprecated.GetName(),
144+
Version: "v1",
145+
Kind: "Deprecated",
156146
Manifest: manifest,
157147
},
158148
},
@@ -168,6 +158,14 @@ var _ = Describe("Install Plan", func() {
168158
Eventually(func() error {
169159
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &csv))
170160
}).Should(Succeed())
161+
Eventually(func() error {
162+
deprecatedCRD := &apiextensionsv1.CustomResourceDefinition{
163+
ObjectMeta: metav1.ObjectMeta{
164+
Name: "deprecateds.operators.io.operator-framework",
165+
},
166+
}
167+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), deprecatedCRD))
168+
}).Should(Succeed())
171169
})
172170

173171
It("creates an Event surfacing the deprecation warning", func() {
@@ -200,9 +198,8 @@ var _ = Describe("Install Plan", func() {
200198
FieldPath: "status.plan[0]",
201199
},
202200
Reason: "AppliedWithWarnings",
203-
Message: fmt.Sprintf("1 warning(s) generated during installation of operator \"%s\" (PodDisruptionBudget \"%s\"): policy/v1beta1 PodDisruptionBudget is deprecated in v1.21+, unavailable in v1.25+; use policy/v1 PodDisruptionBudget", csv.GetName(), pdb.GetName()),
201+
Message: fmt.Sprintf("1 warning(s) generated during installation of operator \"%s\" (Deprecated \"%s\"): operators.io.operator-framework/v1 Deprecated is deprecated", csv.GetName(), deprecated.GetName()),
204202
}))
205-
206203
})
207204

208205
It("increments a metric counting the warning", func() {

Diff for: test/e2e/testdata/deprecated-crd/deprecated.cr.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: operators.io.operator-framework/v1
2+
kind: Deprecated
3+
metadata:
4+
namespace: placeholder
5+
name: foo

Diff for: test/e2e/testdata/deprecated-crd/deprecated.crd.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
e2e.testName: Install Plan when an InstallPlan step contains a deprecated resource
6+
version increments a metric counting the warning
7+
name: deprecateds.operators.io.operator-framework
8+
spec:
9+
conversion:
10+
strategy: None
11+
group: operators.io.operator-framework
12+
names:
13+
kind: Deprecated
14+
listKind: DeprecatedList
15+
plural: deprecateds
16+
singular: deprecated
17+
scope: Namespaced
18+
versions:
19+
- deprecated: true
20+
name: v1
21+
schema:
22+
openAPIV3Schema:
23+
properties:
24+
spec:
25+
description: Spec of a test object.
26+
properties:
27+
foo:
28+
type: string
29+
type: object
30+
status:
31+
description: Spec of a test object.
32+
type: object
33+
type: object
34+
served: true
35+
storage: true

Diff for: test/e2e/util/decode.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package util
2+
3+
import (
4+
"os"
5+
"strings"
6+
7+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
8+
utilyaml "k8s.io/apimachinery/pkg/util/yaml"
9+
)
10+
11+
type clientObjectOption func(client.Object)
12+
13+
func WithNamespace(namespace string) clientObjectOption {
14+
return func(obj client.Object) {
15+
obj.SetNamespace(namespace)
16+
}
17+
}
18+
19+
func DecodeFile(file string, to client.Object, options ...clientObjectOption) (client.Object, error) {
20+
manifest, err := yamlFromFilePath(file)
21+
if err != nil {
22+
return nil, err
23+
}
24+
dec := utilyaml.NewYAMLOrJSONDecoder(strings.NewReader(manifest), 10)
25+
if err := dec.Decode(to); err != nil {
26+
return nil, err
27+
}
28+
29+
return to, nil
30+
}
31+
32+
func yamlFromFilePath(fileName string) (string, error) {
33+
yaml, err := os.ReadFile(fileName)
34+
return string(yaml), err
35+
}

0 commit comments

Comments
 (0)