Skip to content

Commit

Permalink
mkStatefulSet - remove the non longer needed replicas parameter
Browse files Browse the repository at this point in the history
Our controller no longer manages replicas. So simplify the function
by avoiding the need to pass a replicas value to 1.

Change-Id: Iab987d75fe15ce2ef4c269b5abff678575e7484f
  • Loading branch information
morucci committed Nov 21, 2023
1 parent be91ba7 commit b2f319e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions controllers/git_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func (r *SFController) DeployGitServer() bool {
}

// Create the deployment
replicas := int32(1)
dep := r.mkStatefulSet(gsIdent, base.GitServerImage, r.getStorageConfOrDefault(r.cr.Spec.GitServer.Storage), replicas, apiv1.ReadWriteOnce)
dep := r.mkStatefulSet(gsIdent, base.GitServerImage, r.getStorageConfOrDefault(r.cr.Spec.GitServer.Storage), apiv1.ReadWriteOnce)
dep.Spec.Template.ObjectMeta.Annotations = annotations
dep.Spec.Template.Spec.Containers[0].VolumeMounts = []apiv1.VolumeMount{
{
Expand Down
3 changes: 1 addition & 2 deletions controllers/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ func (r *SFController) DeployMariadb() bool {
passName := "mariadb-root-password"
r.EnsureSecretUUID(passName)

replicas := int32(1)
sts := r.mkStatefulSet(mariadbIdent, base.MariabDBImage, r.getStorageConfOrDefault(r.cr.Spec.MariaDB.DBStorage), replicas, apiv1.ReadWriteOnce)
sts := r.mkStatefulSet(mariadbIdent, base.MariabDBImage, r.getStorageConfOrDefault(r.cr.Spec.MariaDB.DBStorage), apiv1.ReadWriteOnce)

sts.Spec.VolumeClaimTemplates = append(
sts.Spec.VolumeClaimTemplates,
Expand Down
3 changes: 1 addition & 2 deletions controllers/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,9 @@ func (r *SFController) DeployNodepoolBuilder(statsdExporterVolume apiv1.Volume,
configScriptVolumeMount,
}

replicas := int32(1)
nb := r.mkStatefulSet(
builderIdent, base.NodepoolBuilderImage, r.getStorageConfOrDefault(r.cr.Spec.Nodepool.Builder.Storage),
replicas, apiv1.ReadWriteOnce)
apiv1.ReadWriteOnce)

nb.Spec.Template.Spec.InitContainers = []apiv1.Container{initContainer}
nb.Spec.Template.Spec.Volumes = volumes
Expand Down
12 changes: 4 additions & 8 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,26 +386,22 @@ func getStorageClassname(storageClassName string) string {
}

// Create a default statefulset.
func (r *SFUtilContext) mkStatefulSet(name string, image string, storageConfig base.StorageConfig, replicas int32, accessMode apiv1.PersistentVolumeAccessMode, nameSuffix ...string) appsv1.StatefulSet {
func (r *SFUtilContext) mkStatefulSet(name string, image string, storageConfig base.StorageConfig, accessMode apiv1.PersistentVolumeAccessMode, nameSuffix ...string) appsv1.StatefulSet {
serviceName := name
if nameSuffix != nil {
serviceName = name + "-" + nameSuffix[0]
}

if replicas == 0 {
replicas = 1
}

container := base.MkContainer(name, image)
pvc := base.MkPVC(name, r.ns, storageConfig, accessMode)
return base.MkStatefulset(name, r.ns, replicas, serviceName, container, pvc)
return base.MkStatefulset(name, r.ns, 1, serviceName, container, pvc)
}

// Create a default headless statefulset.
func (r *SFUtilContext) mkHeadlessSatefulSet(
name string, image string, storageConfig base.StorageConfig,
replicas int32, accessMode apiv1.PersistentVolumeAccessMode) appsv1.StatefulSet {
return r.mkStatefulSet(name, image, storageConfig, replicas, accessMode, "headless")
accessMode apiv1.PersistentVolumeAccessMode) appsv1.StatefulSet {
return r.mkStatefulSet(name, image, storageConfig, accessMode, "headless")
}

func (r *SFUtilContext) IsStatefulSetReady(dep *appsv1.StatefulSet) bool {
Expand Down
3 changes: 1 addition & 2 deletions controllers/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ func (r *SFController) DeployZookeeper() bool {
srvZK := base.MkHeadlessService(zkIdent, r.ns, zkIdent, headlessPorts, zkIdent)
r.GetOrCreate(&srvZK)

replicas := int32(1)
storageConfig := r.getStorageConfOrDefault(r.cr.Spec.Zookeeper.Storage)
zk := r.mkHeadlessSatefulSet(
zkIdent, base.ZookeeperImage, storageConfig, replicas, apiv1.ReadWriteOnce)
zkIdent, base.ZookeeperImage, storageConfig, apiv1.ReadWriteOnce)
// We overwrite the VolumeClaimTemplates set by MkHeadlessStatefulSet to keep the previous volume name
// Previously the default PVC created by MkHeadlessStatefulSet was not used by Zookeeper (not mounted). So to avoid having two Volumes
// and to ensure data persistence during the upgrade we keep the previous naming 'zkIdent + "-data"' and we discard the one
Expand Down
7 changes: 3 additions & 4 deletions controllers/zuul.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ func (r *SFController) EnsureZuulScheduler(initContainers []apiv1.Container, cfg

zsVolumes := mkZuulVolumes("zuul-scheduler", r)

zsReplicas := int32(1)
zs := r.mkStatefulSet("zuul-scheduler", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Scheduler.Storage), zsReplicas, apiv1.ReadWriteOnce)
zs := r.mkStatefulSet("zuul-scheduler", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Scheduler.Storage), apiv1.ReadWriteOnce)
zs.Spec.Template.ObjectMeta.Annotations = annotations
setAdditionalContainers(&zs)
zs.Spec.Template.Spec.Volumes = zsVolumes
Expand Down Expand Up @@ -399,7 +398,7 @@ func (r *SFController) EnsureZuulExecutor(cfg *ini.File) bool {
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
}

ze := r.mkHeadlessSatefulSet("zuul-executor", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Executor.Storage), 1, apiv1.ReadWriteOnce)
ze := r.mkHeadlessSatefulSet("zuul-executor", "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Executor.Storage), apiv1.ReadWriteOnce)
ze.Spec.Template.Spec.Containers = r.mkZuulContainer("zuul-executor")
ze.Spec.Template.Spec.Volumes = mkZuulVolumes("zuul-executor", r)

Expand Down Expand Up @@ -452,7 +451,7 @@ func (r *SFController) EnsureZuulMerger(cfg *ini.File) bool {
"zuul-connections": utils.IniSectionsChecksum(cfg, utils.IniGetSectionNamesByPrefix(cfg, "connection")),
}

zm := r.mkHeadlessSatefulSet(service, "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Merger.Storage), 1, apiv1.ReadWriteOnce)
zm := r.mkHeadlessSatefulSet(service, "", r.getStorageConfOrDefault(r.cr.Spec.Zuul.Merger.Storage), apiv1.ReadWriteOnce)
zm.Spec.Template.Spec.Containers = r.mkZuulContainer(service)
zm.Spec.Template.Spec.Volumes = mkZuulVolumes(service, r)

Expand Down

0 comments on commit b2f319e

Please sign in to comment.