Skip to content

Commit

Permalink
Expose scale subresource to enable HPA's to modify the replicas of In…
Browse files Browse the repository at this point in the history
…finispan CR (#2133)
  • Loading branch information
ZeidH authored Sep 30, 2024
1 parent ce5f149 commit 32d71f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/v1/infinispan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ type InfinispanStatus struct {
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Operator Status"
Operator Operator `json:"operator,omitempty"`
// The Selector used to identify Infinispan cluster pods
// +optional
Selector string `json:"selector"`
}

type OperandPhase string
Expand Down Expand Up @@ -666,6 +669,7 @@ type Operator struct {

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
// +operator-sdk:csv:customresourcedefinitions:displayName="Infinispan Cluster"

// Infinispan is the Schema for the infinispans API
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/infinispan.org_infinispans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2461,11 +2461,18 @@ spec:
description: The secret that contains user credentials.
type: string
type: object
selector:
description: The Operator Selector
type: string
statefulSetName:
type: string
type: object
type: object
served: true
storage: true
subresources:
scale:
labelSelectorPath: .status.selector
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ func ClusterStatefulSet(i *ispnv1.Infinispan, ctx pipeline.Context) {
return
}

selector, err := metav1.LabelSelectorAsSelector(statefulSet.Spec.Selector)

if err != nil {
ctx.Requeue(fmt.Errorf("error retrieving StatefulSet labels: %w", err))
return
}
_ = ctx.UpdateInfinispan(func() {
i.Status.Replicas = &i.Spec.Replicas
i.Status.StatefulSetName = statefulSet.Name
i.Status.Selector = selector.String()
})
}

Expand Down

0 comments on commit 32d71f3

Please sign in to comment.