Skip to content

Commit

Permalink
Update K8s dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
thegridman committed Sep 5, 2023
1 parent 4588a48 commit 4f854da
Show file tree
Hide file tree
Showing 27 changed files with 357 additions and 393 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ COMPATIBLE_SELECTOR = control-plane=coherence
# The GitHub project URL
PROJECT_URL = https://github.com/oracle/coherence-operator

KUBERNETES_DOC_VERSION=v1.26
KUBERNETES_DOC_VERSION=v1.28

# ----------------------------------------------------------------------------------------------------------------------
# The Coherence image to use for deployments that do not specify an image
Expand Down
39 changes: 25 additions & 14 deletions api/v1/coherence_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand Down Expand Up @@ -78,7 +79,7 @@ func SetCommonDefaults(in CoherenceResource) {

// set the default Coherence local port and local port adjust if not present
if spec.Coherence == nil {
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
var lpa = intstr.FromInt32(DefaultUnicastPortAdjust)
spec.Coherence = &CoherenceSpec{
LocalPort: pointer.Int32(DefaultUnicastPort),
LocalPortAdjust: &lpa,
Expand All @@ -88,7 +89,7 @@ func SetCommonDefaults(in CoherenceResource) {
spec.Coherence.LocalPort = pointer.Int32(DefaultUnicastPort)
}
if spec.Coherence.LocalPortAdjust == nil {
lpa := intstr.FromInt(int(DefaultUnicastPortAdjust))
lpa := intstr.FromInt32(DefaultUnicastPortAdjust)
spec.Coherence.LocalPortAdjust = &lpa
}
}
Expand Down Expand Up @@ -128,33 +129,41 @@ var _ webhook.Validator = &Coherence{}
var commonWebHook = CommonWebHook{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateCreate() error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateCreate() (admission.Warnings, error) {
var err error
var warnings admission.Warnings

webhookLogger.Info("validate create", "name", in.Name)
err = commonWebHook.validateReplicas(in)
if err != nil {
return err
return warnings, err
}
err = commonWebHook.validateNodePorts(in)
return err
return warnings, err
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateUpdate(previous runtime.Object) error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateUpdate(previous runtime.Object) (admission.Warnings, error) {
webhookLogger.Info("validate update", "name", in.Name)
var warnings admission.Warnings

if err := commonWebHook.validateReplicas(in); err != nil {
return err
return warnings, err
}
prev := previous.(*Coherence)

if err := commonWebHook.validatePersistence(in, prev); err != nil {
return err
return warnings, err
}
if err := in.validateVolumeClaimTemplates(prev); err != nil {
return err
return warnings, err
}
if err := commonWebHook.validateNodePorts(in); err != nil {
return err
return warnings, err
}

var errorList field.ErrorList
Expand All @@ -163,16 +172,18 @@ func (in *Coherence) ValidateUpdate(previous runtime.Object) error {
errorList = ValidateStatefulSetUpdate(&sts, &stsOld)

if len(errorList) > 0 {
return fmt.Errorf("rejecting update as it would have resulted in an invalid StatefulSet: %v", errorList)
return warnings, fmt.Errorf("rejecting update as it would have resulted in an invalid StatefulSet: %v", errorList)
}

return nil
return warnings, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (in *Coherence) ValidateDelete() error {
// The optional warnings will be added to the response as warning messages.
// Return an error if the object is invalid.
func (in *Coherence) ValidateDelete() (admission.Warnings, error) {
// we do not need to validate deletions
return nil
return nil, nil
}

func (in *Coherence) validateVolumeClaimTemplates(previous *Coherence) error {
Expand Down
27 changes: 16 additions & 11 deletions api/v1/coherence_webhook_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

func (in *CoherenceJob) SetupWebhookWithManager(mgr ctrl.Manager) error {
Expand Down Expand Up @@ -79,30 +80,34 @@ const JobValidatingWebHookPath = "/validate-coherence-oracle-com-v1-coherencejob
var _ webhook.Validator = &CoherenceJob{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (in *CoherenceJob) ValidateCreate() error {
func (in *CoherenceJob) ValidateCreate() (admission.Warnings, error) {
var err error
var warnings admission.Warnings

webhookLogger.Info("validate create", "name", in.Name)
err = commonWebHook.validateReplicas(in)
if err != nil {
return err
return warnings, err
}
err = commonWebHook.validateNodePorts(in)
return err
return warnings, err
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (in *CoherenceJob) ValidateUpdate(previous runtime.Object) error {
func (in *CoherenceJob) ValidateUpdate(previous runtime.Object) (admission.Warnings, error) {
webhookLogger.Info("validate update", "name", in.Name)
var warnings admission.Warnings

if err := commonWebHook.validateReplicas(in); err != nil {
return err
return warnings, err
}
prev := previous.(*CoherenceJob)

if err := commonWebHook.validatePersistence(in, prev); err != nil {
return err
return warnings, err
}
if err := commonWebHook.validateNodePorts(in); err != nil {
return err
return warnings, err
}

var errorList field.ErrorList
Expand All @@ -111,16 +116,16 @@ func (in *CoherenceJob) ValidateUpdate(previous runtime.Object) error {
errorList = ValidateJobUpdate(&job, &jobOld)

if len(errorList) > 0 {
return fmt.Errorf("rejecting update as it would have resulted in an invalid Job: %v", errorList)
return warnings, fmt.Errorf("rejecting update as it would have resulted in an invalid Job: %v", errorList)
}

return nil
return warnings, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (in *CoherenceJob) ValidateDelete() error {
func (in *CoherenceJob) ValidateDelete() (admission.Warnings, error) {
// we do not need to validate deletions
return nil
return nil, nil
}

// ValidateJobUpdate tests if required fields in the Job are set.
Expand Down
34 changes: 17 additions & 17 deletions api/v1/coherence_webhook_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestJobPersistenceModeChangeNotAllowed(t *testing.T) {
},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).To(HaveOccurred())
}

Expand Down Expand Up @@ -315,7 +315,7 @@ func TestJobPersistenceModeChangeAllowedIfReplicasIsZero(t *testing.T) {
},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand Down Expand Up @@ -359,7 +359,7 @@ func TestJobPersistenceModeChangeAllowedIfPreviousReplicasIsZero(t *testing.T) {
},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand Down Expand Up @@ -412,7 +412,7 @@ func TestJobPersistenceVolumeChangeNotAllowed(t *testing.T) {
},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).To(HaveOccurred())
}

Expand All @@ -423,7 +423,7 @@ func TestJobValidateCreateReplicasWhenReplicasIsNil(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -438,7 +438,7 @@ func TestJobValidateCreateReplicasWhenReplicasIsPositive(t *testing.T) {
},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -453,7 +453,7 @@ func TestJobValidateCreateReplicasWhenReplicasIsZero(t *testing.T) {
},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -469,7 +469,7 @@ func TestJobValidateCreateReplicasWhenReplicasIsInvalid(t *testing.T) {
},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).To(HaveOccurred())
}

Expand All @@ -484,7 +484,7 @@ func TestJobValidateUpdateReplicasWhenReplicasIsNil(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -503,7 +503,7 @@ func TestJobValidateUpdateReplicasWhenReplicasIsPositive(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -522,7 +522,7 @@ func TestJobValidateUpdateReplicasWhenReplicasIsZero(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -542,7 +542,7 @@ func TestJobValidateUpdateReplicasWhenReplicasIsInvalid(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).To(HaveOccurred())
}

Expand All @@ -559,7 +559,7 @@ func TestJobValidateVolumeClaimUpdateWhenVolumeClaimsNil(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand All @@ -586,7 +586,7 @@ func TestJobValidateNodePortsOnCreateWithValidPorts(t *testing.T) {
},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).NotTo(HaveOccurred())
}

Expand Down Expand Up @@ -618,7 +618,7 @@ func TestJobValidateNodePortsOnCreateWithInvalidPort(t *testing.T) {
},
}

err := current.ValidateCreate()
_, err := current.ValidateCreate()
g.Expect(err).To(HaveOccurred())
}

Expand Down Expand Up @@ -650,7 +650,7 @@ func TestJobValidateNodePortsOnUpdateWithValidPorts(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).NotTo(HaveOccurred())
}

Expand Down Expand Up @@ -687,6 +687,6 @@ func TestJobValidateNodePortsOnUpdateWithInvalidPort(t *testing.T) {
Spec: coh.CoherenceJobResourceSpec{},
}

err := current.ValidateUpdate(prev)
_, err := current.ValidateUpdate(prev)
g.Expect(err).To(HaveOccurred())
}
Loading

0 comments on commit 4f854da

Please sign in to comment.