Skip to content

Commit cab41aa

Browse files
✨ Add CRD Upgrade Safety Preflight check to the ClusterExtension controller (#979)
* Add CRD Upgrade Safety Preflight check to the ClusterExtension controller Signed-off-by: Rashmi Gottipati <[email protected]> * add nil pointer check Signed-off-by: Rashmi Gottipati <[email protected]> --------- Signed-off-by: Rashmi Gottipati <[email protected]>
1 parent 208e584 commit cab41aa

File tree

7 files changed

+427
-9
lines changed

7 files changed

+427
-9
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ type ClusterExtensionSpec struct {
7979
// the bundle may contain resources that are cluster-scoped or that are
8080
// installed in a different namespace. This namespace is expected to exist.
8181
InstallNamespace string `json:"installNamespace"`
82+
83+
//+kubebuilder:Optional
84+
// Preflight defines the configuration of preflight checks.
85+
Preflight *PreflightConfig `json:"preflight,omitempty"`
86+
}
87+
88+
// PreflightConfig holds the configuration for the preflight checks.
89+
type PreflightConfig struct {
90+
//+kubebuilder:Required
91+
// CRDUpgradeSafety holds necessary configuration for the CRD Upgrade Safety preflight checks.
92+
CRDUpgradeSafety *CRDUpgradeSafetyPreflightConfig `json:"crdUpgradeSafety,omitempty"`
93+
}
94+
95+
// CRDUpgradeSafetyPreflightConfig is the configuration for CRD upgrade safety preflight check.
96+
type CRDUpgradeSafetyPreflightConfig struct {
97+
//+kubebuilder:Required
98+
// Disabled represents the state of the CRD upgrade safety preflight check being disabled/enabled.
99+
Disabled bool `json:"disabled,omitempty"`
82100
}
83101

84102
const (

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/manager/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/spf13/pflag"
2828
"go.uber.org/zap/zapcore"
29+
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
2930
k8slabels "k8s.io/apimachinery/pkg/labels"
3031
"k8s.io/apimachinery/pkg/selection"
3132
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -40,6 +41,7 @@ import (
4041
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
4142
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
4243
registryv1handler "github.com/operator-framework/rukpak/pkg/handler"
44+
crdupgradesafety "github.com/operator-framework/rukpak/pkg/preflights/crdupgradesafety"
4345
"github.com/operator-framework/rukpak/pkg/provisioner/registry"
4446
"github.com/operator-framework/rukpak/pkg/source"
4547
"github.com/operator-framework/rukpak/pkg/storage"
@@ -215,6 +217,16 @@ func main() {
215217
os.Exit(1)
216218
}
217219

220+
aeClient, err := apiextensionsv1client.NewForConfig(mgr.GetConfig())
221+
if err != nil {
222+
setupLog.Error(err, "unable to create apiextensions client")
223+
os.Exit(1)
224+
}
225+
226+
preflights := []controllers.Preflight{
227+
crdupgradesafety.NewPreflight(aeClient.CustomResourceDefinitions()),
228+
}
229+
218230
if err = (&controllers.ClusterExtensionReconciler{
219231
Client: cl,
220232
BundleProvider: catalogClient,
@@ -225,6 +237,7 @@ func main() {
225237
Handler: registryv1handler.HandlerFunc(registry.HandleBundleDeployment),
226238
Finalizers: clusterExtensionFinalizers,
227239
CaCertDir: caCertDir,
240+
Preflights: preflights,
228241
}).SetupWithManager(mgr); err != nil {
229242
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
230243
os.Exit(1)

config/base/crd/bases/olm.operatorframework.io_clusterextensions.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ spec:
5959
maxLength: 48
6060
pattern: ^[a-z0-9]+(-[a-z0-9]+)*$
6161
type: string
62+
preflight:
63+
description: Preflight defines the configuration of preflight checks.
64+
properties:
65+
crdUpgradeSafety:
66+
description: CRDUpgradeSafety holds necessary configuration for
67+
the CRD Upgrade Safety preflight checks.
68+
properties:
69+
disabled:
70+
description: Disabled represents the state of the CRD upgrade
71+
safety preflight check being disabled/enabled.
72+
type: boolean
73+
type: object
74+
type: object
6275
upgradeConstraintPolicy:
6376
default: Enforce
6477
description: Defines the policy for how to handle upgrade constraints

go.mod

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
gopkg.in/yaml.v2 v2.4.0
2222
helm.sh/helm/v3 v3.15.2
2323
k8s.io/api v0.30.1
24+
k8s.io/apiextensions-apiserver v0.30.1
2425
k8s.io/apimachinery v0.30.1
2526
k8s.io/client-go v0.30.1
2627
k8s.io/component-base v0.30.1
@@ -29,6 +30,7 @@ require (
2930
)
3031

3132
require (
33+
carvel.dev/kapp v0.62.1-0.20240508153820-7d8a03ed7ccf // indirect
3234
cloud.google.com/go/compute/metadata v0.3.0 // indirect
3335
dario.cat/mergo v1.0.0 // indirect
3436
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
@@ -86,6 +88,9 @@ require (
8688
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
8789
github.com/containers/ocicrypt v1.1.10 // indirect
8890
github.com/containers/storage v1.54.0 // indirect
91+
github.com/cppforlife/cobrautil v0.0.0-20221130162803-acdfead391ef // indirect
92+
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 // indirect
93+
github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14 // indirect
8994
github.com/cyphar/filepath-securejoin v0.2.5 // indirect
9095
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
9196
github.com/dimchansky/utfbom v1.1.1 // indirect
@@ -138,6 +143,7 @@ require (
138143
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
139144
github.com/hashicorp/errwrap v1.1.0 // indirect
140145
github.com/hashicorp/go-multierror v1.1.1 // indirect
146+
github.com/hashicorp/go-version v1.6.0 // indirect
141147
github.com/huandu/xstrings v1.4.0 // indirect
142148
github.com/imdario/mergo v0.3.16 // indirect
143149
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -147,6 +153,8 @@ require (
147153
github.com/joelanford/ignore v0.1.0 // indirect
148154
github.com/josharian/intern v1.0.0 // indirect
149155
github.com/json-iterator/go v1.1.12 // indirect
156+
github.com/k14s/starlark-go v0.0.0-20200720175618-3a5c849cc368 // indirect
157+
github.com/k14s/ytt v0.36.0 // indirect
150158
github.com/kevinburke/ssh_config v1.2.0 // indirect
151159
github.com/klauspost/compress v1.17.8 // indirect
152160
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
@@ -177,6 +185,7 @@ require (
177185
github.com/opencontainers/go-digest v1.0.0 // indirect
178186
github.com/opencontainers/image-spec v1.1.0 // indirect
179187
github.com/opencontainers/runtime-spec v1.2.0 // indirect
188+
github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11 // indirect
180189
github.com/operator-framework/operator-lib v0.14.0 // indirect
181190
github.com/otiai10/copy v1.14.0 // indirect
182191
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
@@ -200,6 +209,9 @@ require (
200209
github.com/stretchr/objx v0.5.2 // indirect
201210
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
202211
github.com/vbatts/tar-split v0.11.5 // indirect
212+
github.com/vito/go-interact v1.0.1 // indirect
213+
github.com/vmware-tanzu/carvel-kapp-controller v0.50.2 // indirect
214+
github.com/vmware-tanzu/carvel-vendir v0.36.0 // indirect
203215
github.com/xanzy/ssh-agent v0.3.3 // indirect
204216
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
205217
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
@@ -235,7 +247,6 @@ require (
235247
gopkg.in/inf.v0 v0.9.1 // indirect
236248
gopkg.in/warnings.v0 v0.1.2 // indirect
237249
gopkg.in/yaml.v3 v3.0.1 // indirect
238-
k8s.io/apiextensions-apiserver v0.30.1 // indirect
239250
k8s.io/apiserver v0.30.1 // indirect
240251
k8s.io/cli-runtime v0.30.0 // indirect
241252
k8s.io/klog/v2 v2.120.1 // indirect

0 commit comments

Comments
 (0)