Skip to content

Commit

Permalink
Bumped controller-runtime to 0.15.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Oct 27, 2023
1 parent d13f63a commit 6b99e75
Show file tree
Hide file tree
Showing 13 changed files with 870 additions and 404 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.7
CONTROLLER_TOOLS_VERSION ?= v0.11.3
CONTROLLER_TOOLS_VERSION ?= v0.12.1

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
31 changes: 16 additions & 15 deletions api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

internalerrors "github.com/aerospike/aerospike-kubernetes-operator/errors"
"github.com/aerospike/aerospike-management-lib/asconfig"
Expand All @@ -51,65 +52,65 @@ var versionRegex = regexp.MustCompile(`(\d+(\.\d+)+)`)
var _ webhook.Validator = &AerospikeCluster{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (c *AerospikeCluster) ValidateCreate() error {
func (c *AerospikeCluster) ValidateCreate() (admission.Warnings, error) {
aslog := logf.Log.WithName(ClusterNamespacedName(c))

aslog.Info("Validate create")

return c.validate(aslog)
return nil, c.validate(aslog)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (c *AerospikeCluster) ValidateDelete() error {
func (c *AerospikeCluster) ValidateDelete() (admission.Warnings, error) {
aslog := logf.Log.WithName(ClusterNamespacedName(c))

aslog.Info("Validate delete")

return nil
return nil, nil
}

// ValidateUpdate validate update
func (c *AerospikeCluster) ValidateUpdate(oldObj runtime.Object) error {
func (c *AerospikeCluster) ValidateUpdate(oldObj runtime.Object) (admission.Warnings, error) {
aslog := logf.Log.WithName(ClusterNamespacedName(c))

aslog.Info("Validate update")

old := oldObj.(*AerospikeCluster)

if err := c.validate(aslog); err != nil {
return err
return nil, err
}

outgoingVersion, err := GetImageVersion(old.Spec.Image)
if err != nil {
return err
return nil, err
}

incomingVersion, err := GetImageVersion(c.Spec.Image)
if err != nil {
return err
return nil, err
}

if err := deployment.IsValidUpgrade(
outgoingVersion, incomingVersion,
); err != nil {
return fmt.Errorf("failed to start upgrade: %v", err)
return nil, fmt.Errorf("failed to start upgrade: %v", err)
}

// Volume storage update is not allowed but cascadeDelete policy is allowed
if err := old.Spec.Storage.validateStorageSpecChange(&c.Spec.Storage); err != nil {
return fmt.Errorf("storage config cannot be updated: %v", err)
return nil, fmt.Errorf("storage config cannot be updated: %v", err)
}

// MultiPodPerHost cannot be updated
if c.Spec.PodSpec.MultiPodPerHost != old.Spec.PodSpec.MultiPodPerHost {
return fmt.Errorf("cannot update MultiPodPerHost setting")
return nil, fmt.Errorf("cannot update MultiPodPerHost setting")
}

if err := validateNetworkPolicyUpdate(
&old.Spec.AerospikeNetworkPolicy, &c.Spec.AerospikeNetworkPolicy,
); err != nil {
return err
return nil, err
}

// Validate AerospikeConfig update
Expand All @@ -118,19 +119,19 @@ func (c *AerospikeCluster) ValidateUpdate(oldObj runtime.Object) error {
c.Spec.AerospikeConfig, old.Spec.AerospikeConfig,
c.Status.AerospikeConfig,
); err != nil {
return err
return nil, err
}

// Validate Load Balancer update
if err := validateLoadBalancerUpdate(
aslog, c.Spec.SeedsFinderServices.LoadBalancer,
old.Spec.SeedsFinderServices.LoadBalancer,
); err != nil {
return err
return nil, err
}

// Validate RackConfig update
return c.validateRackUpdate(aslog, old)
return nil, c.validateRackUpdate(aslog, old)
}

func (c *AerospikeCluster) validate(aslog logr.Logger) error {
Expand Down
3 changes: 2 additions & 1 deletion api/v1/aerospikecluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
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 All @@ -34,7 +35,7 @@ func (c *AerospikeCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
)
hookServer.Register(
"/mutate-asdb-aerospike-com-v1-aerospikecluster",
&webhook.Admission{Handler: &mutatingHandler{}},
&webhook.Admission{Handler: &mutatingHandler{decoder: admission.NewDecoder(mgr.GetScheme())}},
)

return ctrl.NewWebhookManagedBy(mgr).
Expand Down
7 changes: 3 additions & 4 deletions api/v1/aerospikeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ func (c *AerospikeConfigSpec) UnmarshalJSON(b []byte) error {
}

func (c *AerospikeConfigSpec) DeepCopy() *AerospikeConfigSpec {
src := *c
dst := AerospikeConfigSpec{
dst := &AerospikeConfigSpec{
Value: map[string]interface{}{},
}
lib.DeepCopy(dst.Value, src.Value)
lib.DeepCopy(dst, c)

return &dst
return dst
}
Loading

0 comments on commit 6b99e75

Please sign in to comment.