Skip to content

Commit 7a9179a

Browse files
committed
Fix webhooks
1 parent 465ea4e commit 7a9179a

File tree

7 files changed

+152
-93
lines changed

7 files changed

+152
-93
lines changed

api/v1/coherence_webhook.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ var (
3232
)
3333

3434
func (in *Coherence) SetupWebhookWithManager(mgr ctrl.Manager) error {
35+
hook := &Coherence{}
3536
return ctrl.NewWebhookManagedBy(mgr).
3637
For(in).
38+
WithDefaulter(hook).
39+
WithValidator(hook).
3740
Complete()
3841
}
3942

api/v1/coherence_webhook_image_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
33
* Licensed under the Universal Permissive License v 1.0 as shown at
44
* http://oss.oracle.com/licenses/upl.
55
*/
66

77
package v1_test
88

99
import (
10+
"context"
1011
. "github.com/onsi/gomega"
1112
coh "github.com/oracle/coherence-operator/api/v1"
1213
corev1 "k8s.io/api/core/v1"
@@ -19,7 +20,7 @@ func TestCoherenceWithNoImageNames(t *testing.T) {
1920
g := NewGomegaWithT(t)
2021

2122
c := coh.Coherence{}
22-
_, err := c.ValidateCreate()
23+
_, err := c.ValidateCreate(context.Background(), &c)
2324
g.Expect(err).NotTo(HaveOccurred())
2425
}
2526

@@ -33,7 +34,7 @@ func TestCoherenceCreateWithValidImageName(t *testing.T) {
3334
},
3435
},
3536
}
36-
_, err := c.ValidateCreate()
37+
_, err := c.ValidateCreate(context.Background(), &c)
3738
g.Expect(err).NotTo(HaveOccurred())
3839
}
3940

@@ -47,7 +48,7 @@ func TestCoherenceCreateWithInvalidImageName(t *testing.T) {
4748
},
4849
},
4950
}
50-
_, err := c.ValidateCreate()
51+
_, err := c.ValidateCreate(context.Background(), &c)
5152
g.Expect(err).To(HaveOccurred())
5253
}
5354

@@ -61,7 +62,7 @@ func TestCoherenceCreateWithImageNameWithTrailingSpace(t *testing.T) {
6162
},
6263
},
6364
}
64-
_, err := c.ValidateCreate()
65+
_, err := c.ValidateCreate(context.Background(), &c)
6566
g.Expect(err).To(HaveOccurred())
6667
}
6768

@@ -77,7 +78,7 @@ func TestCoherenceCreateWithValidOperatorImageName(t *testing.T) {
7778
},
7879
},
7980
}
80-
_, err := c.ValidateCreate()
81+
_, err := c.ValidateCreate(context.Background(), &c)
8182
g.Expect(err).NotTo(HaveOccurred())
8283
}
8384

@@ -93,7 +94,7 @@ func TestCoherenceCreateWithInvalidOperatorImageName(t *testing.T) {
9394
},
9495
},
9596
}
96-
_, err := c.ValidateCreate()
97+
_, err := c.ValidateCreate(context.Background(), &c)
9798
g.Expect(err).To(HaveOccurred())
9899
}
99100

@@ -107,7 +108,7 @@ func TestCoherenceUpdateWithInvalidImageName(t *testing.T) {
107108
},
108109
},
109110
}
110-
_, err := c.ValidateUpdate(&c)
111+
_, err := c.ValidateUpdate(context.Background(), &c, &c)
111112
g.Expect(err).To(HaveOccurred())
112113
}
113114

@@ -126,7 +127,7 @@ func TestCoherenceCreateWithValidInitContainerImageName(t *testing.T) {
126127
},
127128
},
128129
}
129-
_, err := c.ValidateCreate()
130+
_, err := c.ValidateCreate(context.Background(), &c)
130131
g.Expect(err).NotTo(HaveOccurred())
131132
}
132133

@@ -145,7 +146,7 @@ func TestCoherenceCreateWithInvalidInitContainerImageName(t *testing.T) {
145146
},
146147
},
147148
}
148-
_, err := c.ValidateCreate()
149+
_, err := c.ValidateCreate(context.Background(), &c)
149150
g.Expect(err).To(HaveOccurred())
150151
}
151152

@@ -164,7 +165,7 @@ func TestCoherenceCreateWithValidSidecarImageName(t *testing.T) {
164165
},
165166
},
166167
}
167-
_, err := c.ValidateCreate()
168+
_, err := c.ValidateCreate(context.Background(), &c)
168169
g.Expect(err).NotTo(HaveOccurred())
169170
}
170171

@@ -183,15 +184,15 @@ func TestCoherenceCreateWithInvalidSidecarImageName(t *testing.T) {
183184
},
184185
},
185186
}
186-
_, err := c.ValidateCreate()
187+
_, err := c.ValidateCreate(context.Background(), &c)
187188
g.Expect(err).To(HaveOccurred())
188189
}
189190

190191
func TestJobWithNoImageNames(t *testing.T) {
191192
g := NewGomegaWithT(t)
192193

193194
c := coh.CoherenceJob{}
194-
_, err := c.ValidateCreate()
195+
_, err := c.ValidateCreate(context.Background(), &c)
195196
g.Expect(err).NotTo(HaveOccurred())
196197
}
197198

@@ -205,7 +206,7 @@ func TestJobCreateWithInvalidImageName(t *testing.T) {
205206
},
206207
},
207208
}
208-
_, err := c.ValidateCreate()
209+
_, err := c.ValidateCreate(context.Background(), &c)
209210
g.Expect(err).To(HaveOccurred())
210211
}
211212

@@ -219,7 +220,7 @@ func TestJobCreateWithValidImageDigest(t *testing.T) {
219220
},
220221
},
221222
}
222-
_, err := c.ValidateCreate()
223+
_, err := c.ValidateCreate(context.Background(), &c)
223224
g.Expect(err).NotTo(HaveOccurred())
224225
}
225226

@@ -233,7 +234,7 @@ func TestJobCreateWithInvalidImageDigest(t *testing.T) {
233234
},
234235
},
235236
}
236-
_, err := c.ValidateCreate()
237+
_, err := c.ValidateCreate(context.Background(), &c)
237238
g.Expect(err).To(HaveOccurred())
238239
}
239240

@@ -247,6 +248,6 @@ func TestJobUpdateWithInvalidImageName(t *testing.T) {
247248
},
248249
},
249250
}
250-
_, err := c.ValidateUpdate(&c)
251+
_, err := c.ValidateUpdate(context.Background(), &c, &c)
251252
g.Expect(err).To(HaveOccurred())
252253
}

0 commit comments

Comments
 (0)