Skip to content

Commit

Permalink
Merge pull request #63 from kubevirt-bot/cherry-pick-62-to-release-4.2
Browse files Browse the repository at this point in the history
[release-4.2] Use 'Replica: 1' on clusters with a single master
  • Loading branch information
beekhof authored Aug 28, 2019
2 parents 3405ca7 + c5c0cfd commit 3a71b9f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/machineremediation/v1alpha1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"machineremediation_types.go",
"machineremediationoperator_types.go",
"register.go",
"replicas.go",
"zz_generated.deepcopy.go",
],
importpath = "kubevirt.io/machine-remediation-operator/pkg/apis/machineremediation/v1alpha1",
Expand All @@ -19,5 +20,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/sigs.k8s.io/controller-runtime/pkg/client:go_default_library",
],
)
35 changes: 35 additions & 0 deletions pkg/apis/machineremediation/v1alpha1/replicas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the healthchecking v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// +groupName=machineremediation.kubevirt.io
package v1alpha1

import (
"context"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
NamespaceOpenShiftMachineAPI = "openshift-machine-api"
MasterNodeRoleLabel = "node-role.kubernetes.io/master"
)

func GetReplicaCount(c client.Client) int32 {
masterNodes := &corev1.NodeList{}
err := c.List(
context.TODO(),
masterNodes,
client.InNamespace(NamespaceOpenShiftMachineAPI),
client.MatchingLabels(map[string]string{MasterNodeRoleLabel: ""}),
)
if err != nil {
return 1
}
if len(masterNodes.Items) < 2 {
return 1
}
return 2
}

4 changes: 2 additions & 2 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func TestReconcile(t *testing.T) {

// update all deployments status to have desired number of replicas
for _, d := range deploys.Items {
d.Status.Replicas = 2
d.Status.UpdatedReplicas = 2
d.Status.Replicas = mrv1.GetReplicaCount(r.client)
d.Status.UpdatedReplicas = mrv1.GetReplicaCount(r.client)
assert.NoError(t, r.client.Update(context.TODO(), &d))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (r *ReconcileMachineRemediationOperator) createOrUpdateDeployment(data *com
}

newDeploy := components.NewDeployment(data)
newDeploy.Spec.Replicas = pointer.Int32Ptr(2)
newDeploy.Spec.Replicas = pointer.Int32Ptr(mrv1.GetReplicaCount(r.client))

oldDeploy, err := r.getDeployment(data.Name, data.Namespace)
if errors.IsNotFound(err) {
Expand Down

0 comments on commit 3a71b9f

Please sign in to comment.