Skip to content

Commit 70b337a

Browse files
authored
Changes to support bundles and catalogs for deployment with OLM
1 parent da8846e commit 70b337a

File tree

114 files changed

+2329
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2329
-694
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ build/
2424
_output/
2525
bin/
2626
bundle/
27+
catalog/
2728
temp/
2829

2930
# OpenShift pre-flight

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ ARG release
1414

1515
LABEL "com.oracle.coherence.application"="operator"
1616
LABEL "com.oracle.coherence.version"="$version"
17+
LABEL "org.opencontainers.image.version"="$version"
1718
LABEL "org.opencontainers.image.revision"="$release"
18-
LABEL "org.opencontainers.image.description"="The Oracle Coherece Kubernetes Operator image ($target)"
1919
LABEL "org.opencontainers.image.source"="https://github.com/oracle/coherence-operator"
2020
LABEL "org.opencontainers.image.authors"="To contact the authors use this link https://github.com/oracle/coherence-operator/discussions"
2121
LABEL "org.opencontainers.image.licenses"="UPL-1.0"
22-
LABEL "org.opencontainers.image.description"="The Oracle Coherece Kubernetes Operator allows full lifecycle management of Oracle Coherence workloads in Kubernetes."
22+
LABEL "org.opencontainers.image.description"="The Oracle Coherence Kubernetes Operator allows full lifecycle management of Oracle Coherence workloads in Kubernetes."
2323

2424
LABEL "name"="Oracle Coherence Kubernetes Operator"
2525
LABEL "vendor"="Oracle"
2626
LABEL "version"="$version"
2727
LABEL "release"="$release"
28-
LABEL "maintainer"="Oracle Coherence Engieering Team"
28+
LABEL "maintainer"="Oracle Coherence Engineering Team"
2929
LABEL "summary"="A Kubernetes Operator for managing Oracle Coherence clusters"
3030
LABEL "description"="The Oracle Coherece Kubernetes Operator allows full lifecycle management of Oracle Coherence workloads in Kubernetes."
3131

Makefile

Lines changed: 186 additions & 65 deletions
Large diffs are not rendered by default.

PROJECT

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
domain: oracle.com
22
layout:
33
- go.kubebuilder.io/v4
4+
multigroup: false
5+
plugins:
6+
manifests.sdk.operatorframework.io/v2: {}
7+
scorecard.sdk.operatorframework.io/v2: {}
48
projectName: coherence-operator
59
repo: github.com/oracle/coherence-operator
610
resources:
7-
-
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
814
controller: true
915
domain: oracle.com
1016
group: coherence.oracle.com
1117
kind: Coherence
1218
path: github.com/oracle/coherence-operator/api/v1
19+
plural: coherence
20+
version: v1
21+
- api:
22+
crdVersion: v1
23+
namespaced: true
24+
controller: true
25+
domain: oracle.com
26+
group: coherence.oracle.com
27+
kind: CoherenceJob
28+
path: github.com/oracle/coherence-operator/api/v1
29+
plural: coherencejob
1330
version: v1
1431
version: "3"
15-
plugins:
16-
manifests.sdk.operatorframework.io/v2: {}
17-
scorecard.sdk.operatorframework.io/v2: {}

api/v1/coherence_webhook.go

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package v1
88

99
import (
10+
"context"
1011
"fmt"
1112
"github.com/distribution/reference"
1213
"github.com/go-test/deep"
@@ -31,8 +32,11 @@ var (
3132
)
3233

3334
func (in *Coherence) SetupWebhookWithManager(mgr ctrl.Manager) error {
35+
hook := &Coherence{}
3436
return ctrl.NewWebhookManagedBy(mgr).
3537
For(in).
38+
WithDefaulter(hook).
39+
WithValidator(hook).
3640
Complete()
3741
}
3842

@@ -44,22 +48,28 @@ const MutatingWebHookPath = "/mutate-coherence-oracle-com-v1-coherence"
4448

4549
// An anonymous var to ensure that the Coherence struct implements webhook.Defaulter
4650
// there will be a compile time error here if this fails.
47-
var _ webhook.Defaulter = &Coherence{}
51+
var _ webhook.CustomDefaulter = &Coherence{}
4852

4953
// Default implements webhook.Defaulter so a webhook will be registered for the type
50-
func (in *Coherence) Default() {
51-
spec, _ := in.GetStatefulSetSpec()
54+
func (in *Coherence) Default(_ context.Context, obj runtime.Object) error {
55+
coh, ok := obj.(*Coherence)
56+
if !ok {
57+
return fmt.Errorf("expected a Coherence instance but got a %T", obj)
58+
}
59+
60+
spec, _ := coh.GetStatefulSetSpec()
5261
// set the default replicas if not present
5362
if spec.Replicas == nil {
5463
spec.SetReplicas(spec.GetReplicas())
5564
}
56-
SetCommonDefaults(in)
65+
SetCommonDefaults(coh)
5766

5867
// apply a label with the hash of the spec - ths must be the last action here to make sure that
5968
// any modifications to the spec field are included in the hash
60-
if hash, applied := EnsureCoherenceHashLabel(in); applied {
69+
if hash, applied := EnsureCoherenceHashLabel(coh); applied {
6170
webhookLogger.Info(fmt.Sprintf("Applied %s label", LabelCoherenceHash), "hash", hash)
6271
}
72+
return nil
6373
}
6474

6575
// SetCommonDefaults sets defaults common to both a Job and StatefulSet
@@ -135,31 +145,36 @@ const ValidatingWebHookPath = "/validate-coherence-oracle-com-v1-coherence"
135145

136146
// An anonymous var to ensure that the Coherence struct implements webhook.Validator
137147
// there will be a compile time error here if this fails.
138-
var _ webhook.Validator = &Coherence{}
148+
var _ webhook.CustomValidator = &Coherence{}
139149
var commonWebHook = CommonWebHook{}
140150

141151
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
142152
// The optional warnings will be added to the response as warning messages.
143153
// Return an error if the object is invalid.
144-
func (in *Coherence) ValidateCreate() (admission.Warnings, error) {
145-
logger := webhookLogger.WithValues("namespace", in.GetNamespace(), "name", in.GetName())
154+
func (in *Coherence) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
155+
coh, ok := obj.(*Coherence)
156+
if !ok {
157+
return nil, fmt.Errorf("expected a Coherence instance but got a %T", obj)
158+
}
159+
160+
logger := webhookLogger.WithValues("namespace", coh.GetNamespace(), "name", coh.GetName())
146161
var warnings admission.Warnings
147162

148-
dt := in.GetDeletionTimestamp()
163+
dt := coh.GetDeletionTimestamp()
149164
if dt != nil {
150165
// the deletion timestamp is set so do nothing
151166
logger.Info("Skipping validation for deleted resource", "deletionTimestamp", *dt)
152167
return warnings, nil
153168
}
154169

155-
webhookLogger.Info("validate create", "name", in.Name)
156-
if err := commonWebHook.validateReplicas(in); err != nil {
170+
webhookLogger.Info("validate create", "name", coh.Name)
171+
if err := commonWebHook.validateReplicas(coh); err != nil {
157172
return warnings, err
158173
}
159-
if err := commonWebHook.validateImages(in); err != nil {
174+
if err := commonWebHook.validateImages(coh); err != nil {
160175
return warnings, err
161176
}
162-
if err := commonWebHook.validateNodePorts(in); err != nil {
177+
if err := commonWebHook.validateNodePorts(coh); err != nil {
163178
return warnings, err
164179
}
165180
return warnings, nil
@@ -168,39 +183,47 @@ func (in *Coherence) ValidateCreate() (admission.Warnings, error) {
168183
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
169184
// The optional warnings will be added to the response as warning messages.
170185
// Return an error if the object is invalid.
171-
func (in *Coherence) ValidateUpdate(previous runtime.Object) (admission.Warnings, error) {
172-
webhookLogger.Info("validate update", "name", in.Name)
173-
logger := webhookLogger.WithValues("namespace", in.GetNamespace(), "name", in.GetName())
186+
func (in *Coherence) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
187+
cohNew, ok := newObj.(*Coherence)
188+
if !ok {
189+
return nil, fmt.Errorf("expected a Coherence instance for new value but got a %T", newObj)
190+
}
191+
cohPrev, ok := oldObj.(*Coherence)
192+
if !ok {
193+
return nil, fmt.Errorf("expected a Coherence instance for old value but got a %T", newObj)
194+
}
195+
196+
webhookLogger.Info("validate update", "name", cohNew.Name)
197+
logger := webhookLogger.WithValues("namespace", cohNew.GetNamespace(), "name", cohNew.GetName())
174198
var warnings admission.Warnings
175199

176-
dt := in.GetDeletionTimestamp()
200+
dt := cohNew.GetDeletionTimestamp()
177201
if dt != nil {
178202
// the deletion timestamp is set so do nothing
179203
logger.Info("Skipping validation for deleted resource", "deletionTimestamp", *dt)
180204
return warnings, nil
181205
}
182206

183-
if err := commonWebHook.validateReplicas(in); err != nil {
207+
if err := commonWebHook.validateReplicas(cohNew); err != nil {
184208
return warnings, err
185209
}
186-
if err := commonWebHook.validateImages(in); err != nil {
210+
if err := commonWebHook.validateImages(cohNew); err != nil {
187211
return warnings, err
188212
}
189-
prev := previous.(*Coherence)
190213

191-
if err := commonWebHook.validatePersistence(in, prev); err != nil {
214+
if err := commonWebHook.validatePersistence(cohNew, cohPrev); err != nil {
192215
return warnings, err
193216
}
194-
if err := in.validateVolumeClaimTemplates(prev); err != nil {
217+
if err := cohNew.validateVolumeClaimTemplates(cohNew, cohPrev); err != nil {
195218
return warnings, err
196219
}
197-
if err := commonWebHook.validateNodePorts(in); err != nil {
220+
if err := commonWebHook.validateNodePorts(cohNew); err != nil {
198221
return warnings, err
199222
}
200223

201224
var errorList field.ErrorList
202-
sts := in.Spec.CreateStatefulSet(in)
203-
stsOld := prev.Spec.CreateStatefulSet(prev)
225+
sts := cohNew.Spec.CreateStatefulSet(cohNew)
226+
stsOld := cohPrev.Spec.CreateStatefulSet(cohPrev)
204227
errorList = ValidateStatefulSetUpdate(&sts, &stsOld)
205228

206229
if len(errorList) > 0 {
@@ -213,27 +236,27 @@ func (in *Coherence) ValidateUpdate(previous runtime.Object) (admission.Warnings
213236
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
214237
// The optional warnings will be added to the response as warning messages.
215238
// Return an error if the object is invalid.
216-
func (in *Coherence) ValidateDelete() (admission.Warnings, error) {
239+
func (in *Coherence) ValidateDelete(context.Context, runtime.Object) (admission.Warnings, error) {
217240
// we do not need to validate deletions
218241
return nil, nil
219242
}
220243

221-
func (in *Coherence) validateVolumeClaimTemplates(previous *Coherence) error {
222-
if in.GetReplicas() == 0 || previous.GetReplicas() == 0 {
244+
func (in *Coherence) validateVolumeClaimTemplates(cohNew, cohPrev *Coherence) error {
245+
if cohNew.GetReplicas() == 0 || cohPrev.GetReplicas() == 0 {
223246
// changes are allowed if current or previous replicas == 0
224247
return nil
225248
}
226249

227-
if len(in.Spec.VolumeClaimTemplates) == 0 && len(previous.Spec.VolumeClaimTemplates) == 0 {
250+
if len(cohNew.Spec.VolumeClaimTemplates) == 0 && len(cohPrev.Spec.VolumeClaimTemplates) == 0 {
228251
// no PVCs in either deployment
229252
return nil
230253
}
231254

232-
diff := deep.Equal(previous.Spec.VolumeClaimTemplates, in.Spec.VolumeClaimTemplates)
255+
diff := deep.Equal(cohPrev.Spec.VolumeClaimTemplates, cohNew.Spec.VolumeClaimTemplates)
233256
if len(diff) != 0 {
234257
return fmt.Errorf("the Coherence resource \"%s\" is invalid: "+
235258
"changes cannot be made to spec.volumeclaimtemplates unless spec.replicas == 0 or the previous"+
236-
" instance of the resource has spec.replicas == 0", in.Name)
259+
" instance of the resource has spec.replicas == 0", cohNew.Name)
237260
}
238261
return nil
239262
}

0 commit comments

Comments
 (0)