Skip to content

Commit

Permalink
Merge pull request #238 from vyzigold/remove_enable_autoscaling
Browse files Browse the repository at this point in the history
Remove "Enable" functionality from autoscaling
  • Loading branch information
openshift-merge-bot[bot] authored Nov 20, 2023
2 parents 5a92493 + 2b86343 commit 5fdafd0
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 224 deletions.
4 changes: 0 additions & 4 deletions api/bases/telemetry.openstack.org_autoscalings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ spec:
- notifierImage
- secret
type: object
enabled:
default: false
description: Allows enabling and disabling the autoscaling feature
type: boolean
heatInstance:
default: heat
description: Heat instance name.
Expand Down
4 changes: 0 additions & 4 deletions api/bases/telemetry.openstack.org_telemetries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,6 @@ spec:
- notifierImage
- secret
type: object
enabled:
default: false
description: Allows enabling and disabling the autoscaling feature
type: boolean
heatInstance:
default: heat
description: Heat instance name.
Expand Down
4 changes: 0 additions & 4 deletions api/v1beta1/autoscaling_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ type AutoscalingSpec struct {
// Heat instance name.
// +kubebuilder:default=heat
HeatInstance string `json:"heatInstance"`

// Allows enabling and disabling the autoscaling feature
// +kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`
}

// AutoscalingStatus defines the observed state of Autoscaling
Expand Down
3 changes: 0 additions & 3 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ const (
// AutoscalingReadyErrorMessage
AutoscalingReadyErrorMessage = "Autoscaling error occured %s"

// AutoscalingReadyErrorMessage
AutoscalingReadyDisabledMessage = "Autoscaling disabled"

// HeatReadyInitMessage
HeatReadyInitMessage = "Heat not started"

Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/telemetry.openstack.org_autoscalings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,6 @@ spec:
- notifierImage
- secret
type: object
enabled:
default: false
description: Allows enabling and disabling the autoscaling feature
type: boolean
heatInstance:
default: heat
description: Heat instance name.
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/telemetry.openstack.org_telemetries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,6 @@ spec:
- notifierImage
- secret
type: object
enabled:
default: false
description: Allows enabling and disabling the autoscaling feature
type: boolean
heatInstance:
default: heat
description: Heat instance name.
Expand Down
12 changes: 0 additions & 12 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,6 @@ rules:
- list
- update
- watch
- apiGroups:
- route.openshift.io
resources:
- routes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- security.openshift.io
resourceNames:
Expand Down
1 change: 0 additions & 1 deletion config/samples/telemetry_v1beta1_autoscaling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ metadata:
app.kubernetes.io/created-by: telemetry-operator
name: autoscaling
spec:
enabled: true
prometheus:
deployPrometheus: false
aodh:
Expand Down
1 change: 0 additions & 1 deletion config/samples/telemetry_v1beta1_telemetry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ metadata:
namespace: openstack
spec:
autoscaling:
enabled: false
prometheus:
deployPrometheus: false
107 changes: 0 additions & 107 deletions controllers/aodh_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand All @@ -38,117 +37,11 @@ import (
util "github.com/openstack-k8s-operators/lib-common/modules/common/util"
mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"

routev1 "github.com/openshift/api/route/v1"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
autoscaling "github.com/openstack-k8s-operators/telemetry-operator/pkg/autoscaling"
)

func (r *AutoscalingReconciler) reconcileDisabledAodh(
ctx context.Context,
instance *telemetryv1.Autoscaling,
helper *helper.Helper,
) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service Aodh disabled")
serviceLabels := map[string]string{
common.AppSelector: autoscaling.ServiceName,
}

// run the Delete to remove all finalizers
ctrlResult, err := r.reconcileDeleteAodh(ctx, instance, helper)
if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}
if err != nil {
return ctrl.Result{}, err
}

// We are disabling autoscaling, not deleting it. We need to
// manually delete all autoscaling resources,
// that were created before

// Delete deployment
depl, err := autoscaling.AodhDeployment(instance, "", serviceLabels)
if err != nil {
return ctrl.Result{}, err
}
err = r.Client.Delete(ctx, depl)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

// Delete db
db, err := mariadbv1.GetDatabaseByName(ctx, helper, autoscaling.ServiceName)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
if !k8s_errors.IsNotFound(err) {
mariadbdatabase := db.GetDatabase()
err = r.Client.Delete(ctx, mariadbdatabase)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}

// Delete keystone service
keystoneService, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, autoscaling.ServiceName, instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
if !k8s_errors.IsNotFound(err) {
err = r.Client.Delete(ctx, keystoneService)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}

// Delete keystone endpoint
keystoneEndpoint, err := keystonev1.GetKeystoneEndpointWithName(ctx, helper, autoscaling.ServiceName, instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
if !k8s_errors.IsNotFound(err) {
err = r.Client.Delete(ctx, keystoneEndpoint)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}

// Delete services
svcs, err := service.GetServicesListWithLabel(ctx, helper, instance.Namespace, serviceLabels)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
if !k8s_errors.IsNotFound(err) {
for _, svc := range svcs.Items {
// NOTE: Using r.Client.Delete() to delete a service ends with:
// "k8s.io/api/core/v1".Service does not implement
// client.Object (DeepCopyObject method has pointer receiver)
serviceClient := helper.GetKClient().CoreV1().Services(instance.Namespace)
err = serviceClient.Delete(ctx, svc.ObjectMeta.Name, metav1.DeleteOptions{})
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
}
}

// Delete public route
route := &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Namespace: instance.Namespace,
Name: autoscaling.ServiceName + "-public",
},
}
err = r.Client.Delete(ctx, route)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
instance.Status.Conditions = condition.Conditions{}
Log.Info(fmt.Sprintf("Reconciled Service Aodh '%s' disable successfully", autoscaling.ServiceName))
return ctrl.Result{}, nil
}

func (r *AutoscalingReconciler) reconcileDeleteAodh(
ctx context.Context,
instance *telemetryv1.Autoscaling,
Expand Down
57 changes: 9 additions & 48 deletions controllers/autoscaling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (r *AutoscalingReconciler) GetLogger(ctx context.Context) logr.Logger {
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneapis,verbs=get;list;watch;
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete;
Expand Down Expand Up @@ -130,23 +129,17 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
if !instance.Spec.Enabled {
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, telemetryv1.AutoscalingReadyDisabledMessage,
)
condition.ReadyCondition, condition.ReadyMessage)
} else {
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
condition.ReadyCondition, condition.ReadyMessage)
} else {
// something is not ready so reset the Ready condition
instance.Status.Conditions.MarkUnknown(
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
// and recalculate it based on the state of the rest of the conditions
instance.Status.Conditions.Set(
instance.Status.Conditions.Mirror(condition.ReadyCondition))
}
// something is not ready so reset the Ready condition
instance.Status.Conditions.MarkUnknown(
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
// and recalculate it based on the state of the rest of the conditions
instance.Status.Conditions.Set(
instance.Status.Conditions.Mirror(condition.ReadyCondition))
}
err := helper.PatchInstance(ctx, instance)
if err != nil {
Expand Down Expand Up @@ -206,42 +199,10 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return r.reconcileDelete(ctx, instance, helper)
}

// Handle service disabled
if !instance.Spec.Enabled {
return r.reconcileDisabled(ctx, instance, helper)
}

// Handle non-deleted clusters
return r.reconcileNormal(ctx, instance, helper)
}

func (r *AutoscalingReconciler) reconcileDisabled(
ctx context.Context,
instance *telemetryv1.Autoscaling,
helper *helper.Helper,
) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service disabled")
ctrlResult, err := r.reconcileDisabledPrometheus(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}
ctrlResult, err = r.reconcileDisabledAodh(ctx, instance, helper)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
return ctrlResult, nil
}
// Set the condition to true, since the service is disabled
for _, c := range instance.Status.Conditions {
instance.Status.Conditions.MarkTrue(c.Type, telemetryv1.AutoscalingReadyDisabledMessage)
}
Log.Info(fmt.Sprintf("Reconciled Service '%s' disable successfully", autoscaling.ServiceName))
return ctrl.Result{}, nil
}

func (r *AutoscalingReconciler) reconcileDelete(
ctx context.Context,
instance *telemetryv1.Autoscaling,
Expand Down
27 changes: 0 additions & 27 deletions controllers/prometheus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,6 @@ import (
autoscaling "github.com/openstack-k8s-operators/telemetry-operator/pkg/autoscaling"
)

func (r *AutoscalingReconciler) reconcileDisabledPrometheus(
ctx context.Context,
instance *telemetryv1.Autoscaling,
helper *helper.Helper,
) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
Log.Info("Reconciling Service Prometheus disabled")
serviceLabels := map[string]string{
common.AppSelector: autoscaling.ServiceName,
}

prom := autoscaling.Prometheus(instance, serviceLabels)
err := r.Client.Delete(ctx, prom)
if err != nil {
if !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, nil
}
}

// Set the condition to true, since the service is disabled
for _, c := range instance.Status.Conditions {
instance.Status.Conditions.MarkTrue(c.Type, telemetryv1.AutoscalingReadyDisabledMessage)
}
Log.Info(fmt.Sprintf("Reconciled Service '%s' disable successfully", autoscaling.ServiceName))
return ctrl.Result{}, nil
}

func (r *AutoscalingReconciler) reconcileDeletePrometheus(
ctx context.Context,
instance *telemetryv1.Autoscaling,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/go-logr/logr v1.3.0
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/openshift/api v3.9.0+incompatible
github.com/openstack-k8s-operators/heat-operator/api v0.1.0
github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20231103182030-0aaa65ca38c7
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20231103151903-a1a0e540408d
Expand Down Expand Up @@ -56,6 +55,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openshift/api v3.9.0+incompatible // indirect
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20231102083359-58e12a1299b2 // indirect
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20231102083359-58e12a1299b2 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"

routev1 "github.com/openshift/api/route/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -64,7 +63,6 @@ func init() {
utilruntime.Must(telemetryv1beta1.AddToScheme(scheme))
utilruntime.Must(obov1.AddToScheme(scheme))
utilruntime.Must(mariadbv1beta1.AddToScheme(scheme))
utilruntime.Must(routev1.AddToScheme(scheme))
utilruntime.Must(memcachedv1.AddToScheme(scheme))
utilruntime.Must(heatv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
Expand Down
1 change: 0 additions & 1 deletion tests/kuttl/suites/autoscaling/tests/01-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: Autoscaling
metadata:
name: telemetry-kuttl
spec:
enabled: true
prometheus:
deployPrometheus: true
aodh:
Expand Down
1 change: 0 additions & 1 deletion tests/kuttl/suites/default/tests/01-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
name: telemetry
spec:
autoscaling:
enabled: true
prometheus:
deployPrometheus: true
aodh:
Expand Down

0 comments on commit 5fdafd0

Please sign in to comment.