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

[RHCLOUD-35554] - Add replica control on deployments #199

Merged
merged 13 commits into from
Oct 17, 2024
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM registry.access.redhat.com/ubi8/go-toolset:1.21 as base
FROM registry.access.redhat.com/ubi8/go-toolset:1.21.13 as base

WORKDIR /workspace

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ build-template: manifests kustomize controller-gen
$(KUSTOMIZE) build config/deployment-template | ./manifest2template.py > deploy.yml

manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type FrontendSpec struct {
ServiceTiles []*ServiceTile `json:"serviceTiles,omitempty" yaml:"serviceTiles,omitempty"`
// Data for the available widgets for the resource
WidgetRegistry []*WidgetEntry `json:"widgetRegistry,omitempty" yaml:"widgetRegistry,omitempty"`
Replicas *int32 `json:"replicas,omitempty" yaml:"replicas,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity. Does this need to be a pointer? I know the check would have to change bellow but I am curious why we prefer pointer here over plain int value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I could be wrong so it isn't a hill I would die on, but as I understood it if the type in the spec is int, then if the property is omitted from the resource then the value will be implicitly set to 0, which would then make my comparison to 0. 0 is a valid value for replicas, and can even be useful in some situations for scaling down and then up again. A corner case, but it has happened. More importantly, it would mean that my logic would be"if the value is 0, set the value to 1" which violates the principle of least surprise. So, I thought this was more correct. That said if any part of my understanding of how all of this hangs together is wrong I'm happy to change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Ok, I was not aware that 0 is a valid replica value. I get it now.

}

var ReconciliationSuccessful = "ReconciliationSuccessful"
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/Dockerfile.pr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.access.redhat.com/ubi8/go-toolset:1.21
FROM registry.access.redhat.com/ubi8/go-toolset:1.21.13
USER 0
RUN dnf install -y openssh-clients git podman make which go jq python3
RUN mkdir /root/go -p
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/cloud.redhat.com_frontends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ spec:
- title
type: object
type: array
replicas:
format: int32
type: integer
searchEntries:
description: The search index partials for the resource
items:
Expand Down
7 changes: 7 additions & 0 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ func (r *FrontendReconciliation) createFrontendDeployment(annotationHashes []map
labeler := utils.GetCustomLabeler(labels, nn, r.Frontend)
labeler(d)

// Set the replicas if specified, otherwise default to 1
if r.Frontend.Spec.Replicas != nil {
d.Spec.Replicas = r.Frontend.Spec.Replicas
} else {
d.Spec.Replicas = utils.Int32Ptr(1)
}

populateVolumes(d, r.Frontend, r.FrontendEnvironment)
populateContainer(d, r.Frontend, r.FrontendEnvironment)
r.populateEnvVars(d, r.FrontendEnvironment)
Expand Down
3 changes: 3 additions & 0 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ objects:
- title
type: object
type: array
replicas:
format: int32
type: integer
searchEntries:
description: The search index partials for the resource
items:
Expand Down
Loading
Loading