Skip to content

Commit 6cfc050

Browse files
committed
Fix deprecated installPlan step resource test
1 parent 898bf42 commit 6cfc050

File tree

14 files changed

+363
-58
lines changed

14 files changed

+363
-58
lines changed

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

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

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=

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-
}
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,9 @@
1+
package catalog
2+
3+
const (
4+
DeprecatedKind = "Deprecated"
5+
)
6+
7+
func init() {
8+
supportedKinds[DeprecatedKind] = struct{}{}
9+
}

test/e2e/installplan_e2e_test.go

+35-27
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,9 @@ 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"
51+
52+
deprecatedv1 "github.com/awgreene/deprecated-crd/api/v1"
5153
)
5254

5355
var _ = Describe("Install Plan", func() {
@@ -76,11 +78,11 @@ var _ = Describe("Install Plan", func() {
7678

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

8688
BeforeEach(func() {
@@ -90,13 +92,8 @@ var _ = Describe("Install Plan", func() {
9092
v, err := dc.ServerVersion()
9193
Expect(err).ToNot(HaveOccurred())
9294

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")
95+
if minor, err := strconv.Atoi(v.Minor); err == nil && minor < 16 {
96+
Skip("test is dependent on CRD v1 introduced at 1.16")
10097
}
10198
})
10299

@@ -107,26 +104,30 @@ var _ = Describe("Install Plan", func() {
107104
counter = metric.Value
108105
}
109106
}
107+
deprecatedCRD, err := util.DecodeFile("./testdata/deprecated-crd/deprecated.crd.yaml", &apiextensionsv1.CustomResourceDefinition{})
108+
Expect(err).NotTo(HaveOccurred())
109+
110+
Expect(ctx.Ctx().Client().Create(context.Background(), deprecatedCRD)).To(Succeed())
110111

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

114-
pdb = policyv1beta1.PodDisruptionBudget{
115-
ObjectMeta: metav1.ObjectMeta{
116-
Name: genName("test-pdb-"),
117-
},
115+
deprecated = deprecatedv1.Deprecated{
118116
TypeMeta: metav1.TypeMeta{
119-
Kind: "PodDisruptionBudget",
120-
APIVersion: policyv1beta1.SchemeGroupVersion.String(),
117+
APIVersion: "operators.io.operator-framework/v1",
118+
Kind: "Deprecated",
119+
},
120+
ObjectMeta: metav1.ObjectMeta{
121+
Namespace: ns.GetName(),
122+
Name: "foo",
121123
},
122-
Spec: policyv1beta1.PodDisruptionBudgetSpec{},
123124
}
124125

125126
scheme := runtime.NewScheme()
126-
Expect(policyv1beta1.AddToScheme(scheme)).To(Succeed())
127+
Expect(deprecatedv1.AddToScheme(scheme)).To(Succeed())
127128
{
128129
var b bytes.Buffer
129-
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&pdb, &b)).To(Succeed())
130+
Expect(k8sjson.NewSerializer(k8sjson.DefaultMetaFactory, scheme, scheme, false).Encode(&deprecated, &b)).To(Succeed())
130131
manifest = b.String()
131132
}
132133

@@ -150,9 +151,9 @@ var _ = Describe("Install Plan", func() {
150151
Resolving: csv.GetName(),
151152
Status: operatorsv1alpha1.StepStatusUnknown,
152153
Resource: operatorsv1alpha1.StepResource{
153-
Name: pdb.GetName(),
154-
Version: pdb.APIVersion,
155-
Kind: pdb.Kind,
154+
Name: deprecated.GetName(),
155+
Version: "v1",
156+
Kind: "Deprecated",
156157
Manifest: manifest,
157158
},
158159
},
@@ -168,6 +169,14 @@ var _ = Describe("Install Plan", func() {
168169
Eventually(func() error {
169170
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &csv))
170171
}).Should(Succeed())
172+
Eventually(func() error {
173+
deprecatedCRD := &apiextensionsv1.CustomResourceDefinition{
174+
ObjectMeta: metav1.ObjectMeta{
175+
Name: "deprecateds.operators.io.operator-framework",
176+
},
177+
}
178+
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), deprecatedCRD))
179+
}).Should(Succeed())
171180
})
172181

173182
It("creates an Event surfacing the deprecation warning", func() {
@@ -200,9 +209,8 @@ var _ = Describe("Install Plan", func() {
200209
FieldPath: "status.plan[0]",
201210
},
202211
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()),
212+
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()),
204213
}))
205-
206214
})
207215

208216
It("increments a metric counting the warning", func() {
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

test/e2e/util/decode.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
func DecodeFile(file string, to client.Object) (client.Object, error) {
12+
manifest, err := yamlFromFilePath(file)
13+
if err != nil {
14+
return nil, err
15+
}
16+
dec := utilyaml.NewYAMLOrJSONDecoder(strings.NewReader(manifest), 10)
17+
if err := dec.Decode(to); err != nil {
18+
return nil, err
19+
}
20+
21+
return to, nil
22+
}
23+
24+
func yamlFromFilePath(fileName string) (string, error) {
25+
yaml, err := os.ReadFile(fileName)
26+
return string(yaml), err
27+
}

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.

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)