Skip to content

Commit 7b014ad

Browse files
committed
Fix deprecated installPlan step resource test
1 parent 898bf42 commit 7b014ad

File tree

12 files changed

+348
-53
lines changed

12 files changed

+348
-53
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: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/operator-framework/operator-lifecycle-manager
33
go 1.19
44

55
require (
6+
github.com/awgreene/deprecated-crd v0.0.0-20221104113733-9325d365f338
67
github.com/blang/semver/v4 v4.0.0
78
github.com/coreos/go-semver v0.3.0
89
github.com/davecgh/go-spew v1.1.1

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:l
167167
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
168168
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0S6Vi7/lbWECcX0j45yZReDZ56BQsrVBOEEY=
169169
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
170+
github.com/awgreene/deprecated-crd v0.0.0-20221104113733-9325d365f338 h1:JZazVWBz5gdejxNSvwD06pxlthcAMOup2omxy40LN74=
171+
github.com/awgreene/deprecated-crd v0.0.0-20221104113733-9325d365f338/go.mod h1:PmWqI9F1lHf+XbJcXbWWA+g6RisiVzk/RdFr1UFjCi8=
170172
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
171173
github.com/aws/aws-sdk-go v1.17.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
172174
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=

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-
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
17+
func init() {
18+
supportedKinds[PrometheusRuleKind] = struct{}{}
19+
supportedKinds[ServiceMonitorKind] = struct{}{}
20+
supportedKinds[PodDisruptionBudgetKind] = struct{}{}
21+
supportedKinds[PriorityClassKind] = struct{}{}
22+
supportedKinds[VerticalPodAutoscalerKind] = struct{}{}
23+
supportedKinds[ConsoleYAMLSampleKind] = struct{}{}
24+
supportedKinds[ConsoleQuickStartKind] = struct{}{}
25+
supportedKinds[ConsoleCLIDownloadKind] = struct{}{}
26+
supportedKinds[ConsoleLinkKind] = struct{}{}
27+
}
28+
29+
// isSupported returns true if OLM supports this type of CustomResource.
30+
func isSupported(kind string) bool {
31+
_, ok := supportedKinds[kind]
32+
return ok
33+
}
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

+78-22
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,8 @@ 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+
51+
deprecatedv1 "github.com/awgreene/deprecated-crd/api/v1"
5152
)
5253

5354
var _ = Describe("Install Plan", func() {
@@ -76,11 +77,11 @@ var _ = Describe("Install Plan", func() {
7677

7778
When("an InstallPlan step contains a deprecated resource version", func() {
7879
var (
79-
csv operatorsv1alpha1.ClusterServiceVersion
80-
plan operatorsv1alpha1.InstallPlan
81-
pdb policyv1beta1.PodDisruptionBudget
82-
manifest string
83-
counter float64
80+
csv operatorsv1alpha1.ClusterServiceVersion
81+
plan operatorsv1alpha1.InstallPlan
82+
deprecated deprecatedv1.Deprecated
83+
manifest string
84+
counter float64
8485
)
8586

8687
BeforeEach(func() {
@@ -107,26 +108,74 @@ var _ = Describe("Install Plan", func() {
107108
counter = metric.Value
108109
}
109110
}
111+
deprecatedCRD := &apiextensionsv1.CustomResourceDefinition{
112+
ObjectMeta: metav1.ObjectMeta{
113+
Name: "deprecateds.operators.io.operator-framework",
114+
},
115+
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
116+
Names: apiextensionsv1.CustomResourceDefinitionNames{
117+
Plural: "deprecateds",
118+
ListKind: "DeprecatedList",
119+
Singular: "deprecated",
120+
Kind: "Deprecated",
121+
},
122+
Scope: "Namespaced",
123+
Group: "operators.io.operator-framework",
124+
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
125+
{
126+
Name: "v1",
127+
Served: true,
128+
Storage: true,
129+
Deprecated: true,
130+
Schema: &apiextensionsv1.CustomResourceValidation{
131+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
132+
Type: "object",
133+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
134+
"spec": {
135+
Type: "object",
136+
Description: "Spec of a test object.",
137+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
138+
"foo": {
139+
Type: "string",
140+
},
141+
},
142+
},
143+
"status": {
144+
Type: "object",
145+
Description: "Spec of a test object.",
146+
},
147+
},
148+
},
149+
},
150+
},
151+
},
152+
},
153+
Status: apiextensionsv1.CustomResourceDefinitionStatus{
154+
StoredVersions: []string{"v1"},
155+
},
156+
}
157+
158+
Expect(ctx.Ctx().Client().Create(context.Background(), deprecatedCRD)).To(Succeed())
110159

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

114-
pdb = policyv1beta1.PodDisruptionBudget{
115-
ObjectMeta: metav1.ObjectMeta{
116-
Name: genName("test-pdb-"),
117-
},
163+
deprecated = deprecatedv1.Deprecated{
118164
TypeMeta: metav1.TypeMeta{
119-
Kind: "PodDisruptionBudget",
120-
APIVersion: policyv1beta1.SchemeGroupVersion.String(),
165+
APIVersion: "operators.io.operator-framework/v1",
166+
Kind: "Deprecated",
167+
},
168+
ObjectMeta: metav1.ObjectMeta{
169+
Namespace: ns.GetName(),
170+
Name: "foo",
121171
},
122-
Spec: policyv1beta1.PodDisruptionBudgetSpec{},
123172
}
124173

125174
scheme := runtime.NewScheme()
126-
Expect(policyv1beta1.AddToScheme(scheme)).To(Succeed())
175+
Expect(deprecatedv1.AddToScheme(scheme)).To(Succeed())
127176
{
128177
var b bytes.Buffer
129-
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&pdb, &b)).To(Succeed())
178+
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&deprecated, &b)).To(Succeed())
130179
manifest = b.String()
131180
}
132181

@@ -150,9 +199,9 @@ var _ = Describe("Install Plan", func() {
150199
Resolving: csv.GetName(),
151200
Status: operatorsv1alpha1.StepStatusUnknown,
152201
Resource: operatorsv1alpha1.StepResource{
153-
Name: pdb.GetName(),
154-
Version: pdb.APIVersion,
155-
Kind: pdb.Kind,
202+
Name: deprecated.GetName(),
203+
Version: "v1",
204+
Kind: "Deprecated",
156205
Manifest: manifest,
157206
},
158207
},
@@ -168,9 +217,17 @@ var _ = Describe("Install Plan", func() {
168217
Eventually(func() error {
169218
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &csv))
170219
}).Should(Succeed())
220+
Eventually(func() error {
221+
deprecatedCRD := &apiextensionsv1.CustomResourceDefinition{
222+
ObjectMeta: metav1.ObjectMeta{
223+
Name: "deprecateds.operators.io.operator-framework",
224+
},
225+
}
226+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), deprecatedCRD))
227+
}).Should(Succeed())
171228
})
172229

173-
It("creates an Event surfacing the deprecation warning", func() {
230+
FIt("creates an Event surfacing the deprecation warning", func() {
174231
Eventually(func() ([]corev1.Event, error) {
175232
var events corev1.EventList
176233
if err := ctx.Ctx().Client().List(context.Background(), &events, client.InNamespace(ns.GetName())); err != nil {
@@ -200,12 +257,11 @@ var _ = Describe("Install Plan", func() {
200257
FieldPath: "status.plan[0]",
201258
},
202259
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()),
260+
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()),
204261
}))
205-
206262
})
207263

208-
It("increments a metric counting the warning", func() {
264+
FIt("increments a metric counting the warning", func() {
209265
Eventually(func() []Metric {
210266
return getMetricsFromPod(ctx.Ctx().KubeClient(), getPodWithLabel(ctx.Ctx().KubeClient(), "app=catalog-operator"))
211267
}).Should(ContainElement(LikeMetric(

Diff for: vendor/github.com/awgreene/deprecated-crd/api/v1/deprecated_types.go

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: vendor/github.com/awgreene/deprecated-crd/api/v1/groupversion_info.go

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)