-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KO-358: Enhance AerospikeBackupService CR with all the possible deployment configuration params #328
base: master
Are you sure you want to change the base?
KO-358: Enhance AerospikeBackupService CR with all the possible deployment configuration params #328
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,8 +55,12 @@ type AerospikeBackupServiceSpec struct { | |
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Backup Service Config" | ||
Config runtime.RawExtension `json:"config"` | ||
|
||
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Pod Configuration" | ||
ServicePodSpec ServicePodSpec `json:"servicePodSpec,omitempty"` | ||
|
||
// Resources defines the requests and limits for the backup service container. | ||
// Resources.Limits should be more than Resources.Requests. | ||
// Deprecated: Resources field is now part of serviceContainerSpec | ||
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resources" | ||
Resources *corev1.ResourceRequirements `json:"resources,omitempty"` | ||
|
||
|
@@ -82,9 +86,7 @@ type AerospikeBackupServiceStatus struct { | |
// It includes: service, backup-policies, storage, secret-agent. | ||
Config runtime.RawExtension `json:"config,omitempty"` | ||
|
||
// Resources defines the requests and limits for the backup service container. | ||
// Resources.Limits should be more than Resources.Requests. | ||
Resources *corev1.ResourceRequirements `json:"resources,omitempty"` | ||
ServicePodSpec ServicePodSpec `json:"servicePodSpec,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
|
||
// SecretMounts is the list of secret to be mounted in the backup service. | ||
SecretMounts []SecretMount `json:"secrets,omitempty"` | ||
|
@@ -103,6 +105,27 @@ type AerospikeBackupServiceStatus struct { | |
Port int32 `json:"port,omitempty"` | ||
} | ||
|
||
type ServicePodSpec struct { | ||
// ServiceContainerSpec configures the backup service container | ||
// created by the operator. | ||
ServiceContainerSpec ServiceContainerSpec `json:"serviceContainer,omitempty"` | ||
|
||
ObjectMeta AerospikeObjectMeta `json:"metadata,omitempty"` | ||
|
||
// SchedulingPolicy controls pods placement on Kubernetes nodes. | ||
SchedulingPolicy `json:",inline"` | ||
|
||
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` | ||
} | ||
|
||
type ServiceContainerSpec struct { | ||
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"` | ||
|
||
// Resources defines the requests and limits for the backup service container. | ||
// Resources.Limits should be more than Resources.Requests. | ||
Resources *corev1.ResourceRequirements `json:"resources,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:metadata:annotations="aerospike-kubernetes-operator/version=3.4.0" | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ package v1beta1 | |||||||||||||||||||||
|
||||||||||||||||||||||
import ( | ||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||
"reflect" | ||||||||||||||||||||||
|
||||||||||||||||||||||
set "github.com/deckarep/golang-set/v2" | ||||||||||||||||||||||
"k8s.io/apimachinery/pkg/runtime" | ||||||||||||||||||||||
|
@@ -28,6 +29,7 @@ import ( | |||||||||||||||||||||
"sigs.k8s.io/yaml" | ||||||||||||||||||||||
|
||||||||||||||||||||||
"github.com/aerospike/aerospike-backup-service/pkg/model" | ||||||||||||||||||||||
asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1" | ||||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (r *AerospikeBackupService) SetupWebhookWithManager(mgr ctrl.Manager) error { | ||||||||||||||||||||||
|
@@ -36,14 +38,20 @@ func (r *AerospikeBackupService) SetupWebhookWithManager(mgr ctrl.Manager) error | |||||||||||||||||||||
Complete() | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Implemented Defaulter interface for future reference | ||||||||||||||||||||||
//nolint:lll // for readability | ||||||||||||||||||||||
//+kubebuilder:webhook:path=/mutate-asdb-aerospike-com-v1beta1-aerospikebackupservice,mutating=true,failurePolicy=fail,sideEffects=None,groups=asdb.aerospike.com,resources=aerospikebackupservices,verbs=create;update,versions=v1beta1,name=maerospikebackupservice.kb.io,admissionReviewVersions=v1 | ||||||||||||||||||||||
|
||||||||||||||||||||||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||
var _ webhook.Defaulter = &AerospikeBackupService{} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// Default implements webhook.Defaulter so a webhook will be registered for the type | ||||||||||||||||||||||
func (r *AerospikeBackupService) Default() { | ||||||||||||||||||||||
absLog := logf.Log.WithName(namespacedName(r)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
absLog.Info("Setting defaults for aerospikeBackupService") | ||||||||||||||||||||||
|
||||||||||||||||||||||
if r.Spec.Resources != nil && r.Spec.ServicePodSpec.ServiceContainerSpec.Resources == nil { | ||||||||||||||||||||||
r.Spec.ServicePodSpec.ServiceContainerSpec.Resources = r.Spec.Resources | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
//nolint:lll // for readability | ||||||||||||||||||||||
|
@@ -65,11 +73,19 @@ func (r *AerospikeBackupService) ValidateCreate() (admission.Warnings, error) { | |||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
warn, err := r.validateServicePodSpec() | ||||||||||||||||||||||
|
||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} else if warn != nil { | ||||||||||||||||||||||
return warn, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||
Comment on lines
+76
to
84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type | ||||||||||||||||||||||
func (r *AerospikeBackupService) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) { | ||||||||||||||||||||||
func (r *AerospikeBackupService) ValidateUpdate(oldObj runtime.Object) (admission.Warnings, error) { | ||||||||||||||||||||||
absLog := logf.Log.WithName(namespacedName(r)) | ||||||||||||||||||||||
|
||||||||||||||||||||||
absLog.Info("Validate update") | ||||||||||||||||||||||
|
@@ -82,6 +98,14 @@ func (r *AerospikeBackupService) ValidateUpdate(_ runtime.Object) (admission.War | |||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
warn, err := r.validateServicePodSpec() | ||||||||||||||||||||||
|
||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} else if warn != nil { | ||||||||||||||||||||||
return warn, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||
Comment on lines
+101
to
109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -139,3 +163,59 @@ func (r *AerospikeBackupService) validateBackupServiceSecrets() error { | |||||||||||||||||||||
|
||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (r *AerospikeBackupService) validateServicePodSpec() (admission.Warnings, error) { | ||||||||||||||||||||||
warn, err := r.validateResourcesField() | ||||||||||||||||||||||
if warn != nil { | ||||||||||||||||||||||
return warn, nil | ||||||||||||||||||||||
} else if err != nil { | ||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} | ||||||||||||||||||||||
Comment on lines
+169
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of warning, we don't have to return immediately as it's not an error. |
||||||||||||||||||||||
|
||||||||||||||||||||||
if err := r.validateResourceLimitsAndRequests(); err != nil { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Club |
||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
if err := validateObjectMeta(&r.Spec.ServicePodSpec.ObjectMeta); err != nil { | ||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
func (r *AerospikeBackupService) validateResourcesField() (admission.Warnings, error) { | ||||||||||||||||||||||
if r.Spec.Resources != nil && r.Spec.ServicePodSpec.ServiceContainerSpec.Resources != nil { | ||||||||||||||||||||||
if !reflect.DeepEqual(r.Spec.Resources, r.Spec.ServicePodSpec.ServiceContainerSpec.Resources) { | ||||||||||||||||||||||
return nil, fmt.Errorf("resources mismatched, different resources requirements shouldn't be allowed") | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Update placeholder of path in the error msg something like |
||||||||||||||||||||||
} else { | ||||||||||||||||||||||
return []string{"resources field in spec is deprecated, " + | ||||||||||||||||||||||
"resources field is now part of servicePodSpec.serviceContainer"}, nil | ||||||||||||||||||||||
Comment on lines
+190
to
+191
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
func (r *AerospikeBackupService) validateResourceLimitsAndRequests() error { | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think k8s native pkg has some validation funcs related to resource requirements. |
||||||||||||||||||||||
if r.Spec.ServicePodSpec.ServiceContainerSpec.Resources != nil { | ||||||||||||||||||||||
resources := r.Spec.ServicePodSpec.ServiceContainerSpec.Resources | ||||||||||||||||||||||
if resources.Limits != nil && resources.Requests != nil && | ||||||||||||||||||||||
((resources.Limits.Cpu().Cmp(*resources.Requests.Cpu()) < 0) || | ||||||||||||||||||||||
(resources.Limits.Memory().Cmp(*resources.Requests.Memory()) < 0)) { | ||||||||||||||||||||||
return fmt.Errorf("resources.Limits cannot be less than resource.Requests. Resources %v", | ||||||||||||||||||||||
resources) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} | ||||||||||||||||||||||
func validateObjectMeta(objectMeta *AerospikeObjectMeta) error { | ||||||||||||||||||||||
for label := range objectMeta.Labels { | ||||||||||||||||||||||
if label == asdbv1.AerospikeAppLabel || label == asdbv1.AerospikeCustomResourceLabel { | ||||||||||||||||||||||
return fmt.Errorf( | ||||||||||||||||||||||
"label: %s is automatically defined by operator and shouldn't be specified by user", | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
label, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return nil | ||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.