Skip to content

Commit

Permalink
Removing autoscaling annotation support (#6885)
Browse files Browse the repository at this point in the history
* removing autoscaling annotation support
  • Loading branch information
kvalliyurnatt authored Jun 7, 2023
1 parent 7af92ec commit 4a6381a
Show file tree
Hide file tree
Showing 39 changed files with 182 additions and 3,430 deletions.
59 changes: 0 additions & 59 deletions pkg/apis/elasticsearch/v1/elasticsearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
package v1

import (
"encoding/json"
"strings"

"github.com/blang/semver/v4"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1"
v1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1alpha1"
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/hash"
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/pointer"
"github.com/elastic/cloud-on-k8s/v2/pkg/utils/set"
Expand Down Expand Up @@ -451,63 +449,6 @@ func (es Elasticsearch) IsAutoscalingAnnotationSet() bool {
return ok
}

// AutoscalingAnnotation returns the autoscaling spec in the Elasticsearch manifest.
// Deprecated: the autoscaling annotation has been deprecated in favor of the ElasticsearchAutoscaler custom resource.
func (es Elasticsearch) AutoscalingAnnotation() string {
return es.Annotations[ElasticsearchAutoscalingSpecAnnotationName]
}

var _ v1alpha1.AutoscalingResource = &Elasticsearch{}

// AutoscalingSpec is the root object of the autoscaling specification in the Elasticsearch resource definition.
// +kubebuilder:object:generate=false
type AutoscalingSpec struct {
AutoscalingPolicySpecs v1alpha1.AutoscalingPolicySpecs `json:"policies"`

// PollingPeriod is the period at which to synchronize and poll the Elasticsearch autoscaling API.
PollingPeriod *metav1.Duration `json:"pollingPeriod"`

// Elasticsearch is stored in the autoscaling spec for convenience. It should be removed once the autoscaling spec is
// fully part of the Elasticsearch specification.
Elasticsearch Elasticsearch `json:"-"`
}

func (es Elasticsearch) GetAutoscalingPolicySpecs() (v1alpha1.AutoscalingPolicySpecs, error) {
autoscalingSpecification, err := es.GetAutoscalingSpecificationFromAnnotation()
if err != nil {
return nil, err
}
return autoscalingSpecification.AutoscalingPolicySpecs, nil
}

func (es Elasticsearch) GetPollingPeriod() (*metav1.Duration, error) {
autoscalingSpecification, err := es.GetAutoscalingSpecificationFromAnnotation()
if err != nil {
return nil, err
}
return autoscalingSpecification.PollingPeriod, nil
}

func (es Elasticsearch) GetElasticsearchAutoscalerStatus() (v1alpha1.ElasticsearchAutoscalerStatus, error) {
autoscalingStatus, err := ElasticsearchAutoscalerStatusFrom(es)
if err != nil {
return v1alpha1.ElasticsearchAutoscalerStatus{}, err
}
return autoscalingStatus, nil
}

// GetAutoscalingSpecificationFromAnnotation unmarshal autoscaling specifications from an Elasticsearch resource.
// Deprecated: the autoscaling annotation has been deprecated in favor of the ElasticsearchAutoscaler custom resource.
func (es Elasticsearch) GetAutoscalingSpecificationFromAnnotation() (AutoscalingSpec, error) {
autoscalingSpec := AutoscalingSpec{}
if len(es.AutoscalingAnnotation()) == 0 {
return autoscalingSpec, nil
}
err := json.Unmarshal([]byte(es.AutoscalingAnnotation()), &autoscalingSpec)
autoscalingSpec.Elasticsearch = es
return autoscalingSpec, err
}

func (es Elasticsearch) SecureSettings() []commonv1.SecretSource {
return es.Spec.SecureSettings
}
Expand Down
13 changes: 2 additions & 11 deletions pkg/controller/autoscaling/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@ import (
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/operator"
)

// Add creates both legacy and new Elasticsearch autoscaling controllers, and adds them to the Manager with default RBAC.
// Add creates a new Elasticsearch autoscaling controllers, and adds it to the Manager with default RBAC.
// The Manager will set fields on the Controllers and Start them when the Manager is Started.
func Add(mgr manager.Manager, p operator.Parameters) error {
legacyReconciler, reconciler := elasticsearch.NewReconcilers(mgr, p)
legacyController, err := common.NewController(mgr, elasticsearch.LegacyControllerName, legacyReconciler, p)
if err != nil {
return err
}

// The deprecated/legacy controller watches for changes on Elasticsearch clusters.
if err := legacyController.Watch(source.Kind(mgr.GetCache(), &esv1.Elasticsearch{}), &handler.EnqueueRequestForObject{}); err != nil {
return err
}
reconciler := elasticsearch.NewReconciler(mgr, p)

// The CRD based controller watches for changes on both the ElasticsearchAutoscaler CRD, and on the Elasticsearch resources to make sure the
// NodeSets resources are reconciled with the required resources.
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/autoscaling/elasticsearch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ type ReconcileElasticsearchAutoscaler struct {
Watches watches.DynamicWatches
}

// NewReconcilers returns both a legacy (ES annotation based) and new (CRD based) reconcile.Reconciler
func NewReconcilers(mgr manager.Manager, params operator.Parameters) (*ReconcileElasticsearchAutoscalingAnnotation, *ReconcileElasticsearchAutoscaler) {
// NewReconciler returns a new autoscaling reconcile.Reconciler
func NewReconciler(mgr manager.Manager, params operator.Parameters) *ReconcileElasticsearchAutoscaler {
c := mgr.GetClient()
reconcileAutoscaling := baseReconcileAutoscaling{
Client: c,
Expand All @@ -90,11 +90,10 @@ func NewReconcilers(mgr manager.Manager, params operator.Parameters) (*Reconcile
recorder: mgr.GetEventRecorderFor(ControllerName),
licenseChecker: license.NewLicenseChecker(c, params.OperatorNamespace),
}
return &ReconcileElasticsearchAutoscalingAnnotation{reconcileAutoscaling.withRecorder(mgr.GetEventRecorderFor(LegacyControllerName))},
&ReconcileElasticsearchAutoscaler{
baseReconcileAutoscaling: reconcileAutoscaling.withRecorder(mgr.GetEventRecorderFor(ControllerName)),
Watches: watches.NewDynamicWatches(),
}
return &ReconcileElasticsearchAutoscaler{
baseReconcileAutoscaling: reconcileAutoscaling.withRecorder(mgr.GetEventRecorderFor(ControllerName)),
Watches: watches.NewDynamicWatches(),
}
}

func dynamicWatchName(request reconcile.Request) string {
Expand Down
166 changes: 0 additions & 166 deletions pkg/controller/autoscaling/elasticsearch/controller_legacy.go

This file was deleted.

Loading

0 comments on commit 4a6381a

Please sign in to comment.