Skip to content

Commit

Permalink
Merge pull request #64 from cynepco3hahue/HCO_fixes
Browse files Browse the repository at this point in the history
Move getReplicasCount method from the apis package
  • Loading branch information
Artyom Lukianov authored Sep 1, 2019
2 parents 0c24d72 + 3546ca4 commit 602581a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 41 deletions.
2 changes: 0 additions & 2 deletions pkg/apis/machineremediation/v1alpha1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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 @@ -20,6 +19,5 @@ 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: 0 additions & 35 deletions pkg/apis/machineremediation/v1alpha1/replicas.go

This file was deleted.

2 changes: 2 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
ControllerMachineHealthCheck = "machine-health-check"
// ControllerMachineRemediation contains the name of achineRemediation controller
ControllerMachineRemediation = "machine-remediation"
//MasterRoleLabel contains master role label
MasterRoleLabel = "node-role.kubernetes.io/master"
// NamespaceOpenshiftMachineAPI contains namespace name for the machine-api componenets under the OpenShift cluster
NamespaceOpenshiftMachineAPI = "openshift-machine-api"
)
2 changes: 1 addition & 1 deletion pkg/operator/components/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func NewClusterServiceVersion(data *ClusterServiceVersionData) (*csvv1.ClusterSe
DisplayName: "Machine Remediation Operator",
Description: description,
Keywords: []string{"remediation", "fencing", "HA", "health", "cluster-api"},
Version: version.OperatorVersion{ *csvVersion },
Version: version.OperatorVersion{Version: *csvVersion},
Maturity: "alpha",
Maintainers: []csvv1.Maintainer{{
Name: "KubeVirt project",
Expand Down
7 changes: 5 additions & 2 deletions pkg/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ func TestReconcile(t *testing.T) {

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

d.Status.Replicas = replicas
d.Status.UpdatedReplicas = replicas
assert.NoError(t, r.client.Update(context.TODO(), &d))
}

Expand Down
26 changes: 25 additions & 1 deletion pkg/operator/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import (
"k8s.io/utils/pointer"

mrv1 "kubevirt.io/machine-remediation-operator/pkg/apis/machineremediation/v1alpha1"
"kubevirt.io/machine-remediation-operator/pkg/consts"
"kubevirt.io/machine-remediation-operator/pkg/operator/components"

"sigs.k8s.io/controller-runtime/pkg/client"
)

func (r *ReconcileMachineRemediationOperator) getDeployment(name string, namespace string) (*appsv1.Deployment, error) {
Expand Down Expand Up @@ -48,7 +51,12 @@ func (r *ReconcileMachineRemediationOperator) createOrUpdateDeployment(data *com
}

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

replicas, err := r.getReplicasCount()
if err != nil {
return err
}
newDeploy.Spec.Replicas = pointer.Int32Ptr(replicas)

oldDeploy, err := r.getDeployment(data.Name, data.Namespace)
if errors.IsNotFound(err) {
Expand All @@ -72,6 +80,22 @@ func (r *ReconcileMachineRemediationOperator) createOrUpdateDeployment(data *com
return r.client.Update(context.TODO(), newDeploy)
}

func (r *ReconcileMachineRemediationOperator) getReplicasCount() (int32, error) {
masterNodes := &corev1.NodeList{}
if err := r.client.List(
context.TODO(),
masterNodes,
client.InNamespace(consts.NamespaceOpenshiftMachineAPI),
client.MatchingLabels(map[string]string{consts.MasterRoleLabel: ""}),
); err != nil {
return 0, err
}
if len(masterNodes.Items) < 2 {
return 1, nil
}
return 2, nil
}

func (r *ReconcileMachineRemediationOperator) getOperatorImageRepository() (string, error) {
ns, err := getOperatorNamespace()
if err != nil {
Expand Down

0 comments on commit 602581a

Please sign in to comment.