Skip to content
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

Exposing scale subresource to enable HPA's to modify the replicas of Infinispan CR #2133

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
ZeidH marked this conversation as resolved.
Show resolved Hide resolved
}

type OperandPhase string
Expand Down Expand Up @@ -663,6 +666,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 @@ -2457,11 +2457,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
Loading