Skip to content

Commit

Permalink
add status tag
Browse files Browse the repository at this point in the history
  • Loading branch information
zszazi committed Nov 10, 2024
1 parent c8981b0 commit a35e45b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 72 deletions.
7 changes: 5 additions & 2 deletions api/v1alpha1/chronoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
const (
SUCCESS = "Success"
FAILED = "Failed"
)

// ChronoScalerSpec defines the desired state of ChronoScaler
type ChronoScalerSpec struct {
Expand All @@ -32,6 +34,7 @@ type NamespacedName struct {
type ChronoScalerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Status string `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/api.zszazi.github.io_chronoscalers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ spec:
type: object
status:
description: ChronoScalerStatus defines the observed state of ChronoScaler
properties:
status:
description: |-
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Important: Run "make" to regenerate code after modifying this file
type: string
type: object
type: object
served: true
Expand Down
4 changes: 2 additions & 2 deletions config/samples/api_v1alpha1_chronoscaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ metadata:
name: chronoscaler-sample
spec:
start: "9h23m"
end: "14h41m"
end: "21h41m"
replicas: 3
defaultReplicas: 2
defaultReplicas: 1
deployments:
- name: nginx
namespace: default
6 changes: 6 additions & 0 deletions internal/controller/chronoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (r *ChronoScalerReconciler) Reconcile(ctx context.Context, req ctrl.Request

deployment.Spec.Replicas = &targetReplicas
err := r.Update(ctx, deployment)
if err != nil {
scaler.Status.Status = apiv1alpha1.FAILED
return ctrl.Result{}, err
}
scaler.Status.Status = apiv1alpha1.SUCCESS
err = r.Status().Update(ctx, scaler)
if err != nil {
return ctrl.Result{}, err
}
Expand Down
68 changes: 0 additions & 68 deletions internal/controller/chronoscaler_controller_test.go

This file was deleted.

0 comments on commit a35e45b

Please sign in to comment.