From 7613f8040889f81d44575fe6d2b89a4b800ded89 Mon Sep 17 00:00:00 2001 From: Artyom Lukianov Date: Tue, 3 Sep 2019 17:13:51 +0300 Subject: [PATCH] Update MRO version (#271) --- Gopkg.lock | 6 +- Gopkg.toml | 2 +- deploy/cluster_role.yaml | 10 ++- deploy/cluster_role_binding.yaml | 2 +- ...operator.v0.0.2.clusterserviceversion.yaml | 36 +++++--- deploy/operator.yaml | 26 +++--- deploy/service_account.yaml | 2 +- hack/deploy.sh | 7 +- .../cmd/machine-remediation-operator/main.go | 14 ++- .../machine-remediation-operator/doc.go | 21 +++++ .../pkg/consts/consts.go | 2 + .../machinehealthcheck_controller.go | 86 ++++++++++++++++++- .../pkg/operator/components/csv.go | 4 +- .../pkg/operator/components/deployments.go | 19 ++-- .../pkg/operator/components/rbac.go | 13 +++ .../pkg/operator/resources.go | 26 +++++- .../pkg/utils/testing/testing.go | 9 +- 17 files changed, 228 insertions(+), 57 deletions(-) create mode 100644 vendor/kubevirt.io/machine-remediation-operator/doc.go diff --git a/Gopkg.lock b/Gopkg.lock index bffb4afcfb..3061a2aa29 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1257,7 +1257,7 @@ version = "v0.20.4" [[projects]] - digest = "1:d8afbdbd0254ba639d9ca43779192de86c08edc3a14b594c5589d767a198883b" + digest = "1:b6b1d9e3e98a790af2d30428c80127cc9f41a19188e39aad29935756c608606d" name = "kubevirt.io/machine-remediation-operator" packages = [ "pkg/apis/machineremediation", @@ -1265,8 +1265,8 @@ "pkg/operator/components", ] pruneopts = "NT" - revision = "4a7f171fefc3e4bb8ca50634c3e76e6803e4c5a6" - version = "v0.3.7" + revision = "e023ed6cb4038ded6651f8a457aab37af1dba4ab" + version = "v0.3.10" [[projects]] digest = "1:06035489efbd51ccface65fc878ceeb849aba05b2f9443c8993f363fc96e80ac" diff --git a/Gopkg.toml b/Gopkg.toml index f81d7d4e4e..8c112479e3 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -60,7 +60,7 @@ required = [ [[override]] name = "kubevirt.io/machine-remediation-operator" - version = "=v0.3.7" + version = "=v0.3.10" [[override]] name = "k8s.io/api" diff --git a/deploy/cluster_role.yaml b/deploy/cluster_role.yaml index 1a3aacf237..ec3e8dac61 100644 --- a/deploy/cluster_role.yaml +++ b/deploy/cluster_role.yaml @@ -841,7 +841,7 @@ kind: ClusterRole metadata: labels: machineremediation.kubevirt.io: "" - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 name: machine-remediation-operator rules: - apiGroups: @@ -854,6 +854,14 @@ rules: - list - update - watch +- apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch - apiGroups: - "" resources: diff --git a/deploy/cluster_role_binding.yaml b/deploy/cluster_role_binding.yaml index cdda69871c..a602c22f6d 100644 --- a/deploy/cluster_role_binding.yaml +++ b/deploy/cluster_role_binding.yaml @@ -123,7 +123,7 @@ kind: ClusterRoleBinding metadata: labels: machineremediation.kubevirt.io: "" - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 name: machine-remediation-operator roleRef: apiGroup: rbac.authorization.k8s.io diff --git a/deploy/olm-catalog/kubevirt-hyperconverged/0.0.2/kubevirt-hyperconverged-operator.v0.0.2.clusterserviceversion.yaml b/deploy/olm-catalog/kubevirt-hyperconverged/0.0.2/kubevirt-hyperconverged-operator.v0.0.2.clusterserviceversion.yaml index 3ade1983e3..96a691c5dd 100644 --- a/deploy/olm-catalog/kubevirt-hyperconverged/0.0.2/kubevirt-hyperconverged-operator.v0.0.2.clusterserviceversion.yaml +++ b/deploy/olm-catalog/kubevirt-hyperconverged/0.0.2/kubevirt-hyperconverged-operator.v0.0.2.clusterserviceversion.yaml @@ -95,7 +95,7 @@ metadata: categories: OpenShift Optional certified: 'false' containerImage: quay.io/kubevirt/hyperconverged-cluster-operator:latest - createdAt: 2019-09-02 19:50:03.604263223 +0200 CEST m=+0.021864303 + createdAt: 2019-09-03 15:43:27.61039013 +0300 IDT m=+0.025400476 description: Creates and maintains a HyperConverged KubeVirt Deployment repository: https://github.com/kubevirt/hyperconverged-cluster-operator support: 'false' @@ -1065,6 +1065,14 @@ spec: - list - update - watch + - apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch - apiGroups: - "" resources: @@ -1474,25 +1482,27 @@ spec: selector: matchLabels: machineremediation.kubevirt.io: machine-remediation-operator - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 strategy: type: RollingUpdate template: metadata: labels: machineremediation.kubevirt.io: machine-remediation-operator - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 spec: affinity: podAntiAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchExpressions: - - key: machineremediation.kubevirt.io - operator: In - values: - - machine-remediation-operator - topologyKey: kubernetes.io/hostname + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: machineremediation.kubevirt.io + operator: In + values: + - machine-remediation-operator + topologyKey: kubernetes.io/hostname + weight: 50 containers: - args: - --logtostderr=true @@ -1502,8 +1512,8 @@ spec: - /usr/bin/machine-remediation-operator env: - name: OPERATOR_VERSION - value: v0.3.7 - image: kubevirt/machine-remediation-operator:v0.3.7 + value: v0.3.10 + image: kubevirt/machine-remediation-operator:v0.3.10 imagePullPolicy: IfNotPresent name: machine-remediation-operator resources: diff --git a/deploy/operator.yaml b/deploy/operator.yaml index a027f85b61..4e6f42c4d7 100644 --- a/deploy/operator.yaml +++ b/deploy/operator.yaml @@ -231,7 +231,7 @@ spec: selector: matchLabels: machineremediation.kubevirt.io: machine-remediation-operator - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 strategy: type: RollingUpdate template: @@ -239,18 +239,20 @@ spec: creationTimestamp: null labels: machineremediation.kubevirt.io: machine-remediation-operator - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 spec: affinity: podAntiAffinity: - requiredDuringSchedulingIgnoredDuringExecution: - - labelSelector: - matchExpressions: - - key: machineremediation.kubevirt.io - operator: In - values: - - machine-remediation-operator - topologyKey: kubernetes.io/hostname + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + labelSelector: + matchExpressions: + - key: machineremediation.kubevirt.io + operator: In + values: + - machine-remediation-operator + topologyKey: kubernetes.io/hostname + weight: 50 containers: - args: - --logtostderr=true @@ -260,8 +262,8 @@ spec: - /usr/bin/machine-remediation-operator env: - name: OPERATOR_VERSION - value: v0.3.7 - image: kubevirt/machine-remediation-operator:v0.3.7 + value: v0.3.10 + image: kubevirt/machine-remediation-operator:v0.3.10 imagePullPolicy: IfNotPresent name: machine-remediation-operator resources: diff --git a/deploy/service_account.yaml b/deploy/service_account.yaml index dbe727e19a..6feaa4ee00 100644 --- a/deploy/service_account.yaml +++ b/deploy/service_account.yaml @@ -53,6 +53,6 @@ kind: ServiceAccount metadata: labels: machineremediation.kubevirt.io: "" - machineremediation.kubevirt.io/version: v0.3.7 + machineremediation.kubevirt.io/version: v0.3.10 name: machine-remediation-operator namespace: kubevirt-hyperconverged diff --git a/hack/deploy.sh b/hack/deploy.sh index 3f10e0df9d..7b43ffb088 100755 --- a/hack/deploy.sh +++ b/hack/deploy.sh @@ -104,11 +104,10 @@ for dep in cdi-apiserver cdi-deployment cdi-uploadproxy virt-api virt-controller "${CMD}" wait deployment/"${dep}" --for=condition=Available --timeout="360s" || CONTAINER_ERRORED+="${dep} " done -# TODO: When MRO conditions stabilize, uncomment. Create a follow up PR after this merges to uncomment # Wait for machine-remediation controllers under the openshift-machine-api namespace -# for dep in machine-health-check machine-disruption-budget machine-remediation; do -# "${CMD}" -n openshift-machine-api wait deployment/"${dep}" --for=condition=Available --timeout="360s" || CONTAINER_ERRORED+="${dep} " -# done +for dep in machine-health-check machine-disruption-budget machine-remediation; do + "${CMD}" -n openshift-machine-api wait deployment/"${dep}" --for=condition=Available --timeout="360s" || CONTAINER_ERRORED+="${dep} " +done if [ -z "$CONTAINER_ERRORED" ]; then echo "SUCCESS" diff --git a/vendor/kubevirt.io/machine-remediation-operator/cmd/machine-remediation-operator/main.go b/vendor/kubevirt.io/machine-remediation-operator/cmd/machine-remediation-operator/main.go index 982c49e14c..1f27797b44 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/cmd/machine-remediation-operator/main.go +++ b/vendor/kubevirt.io/machine-remediation-operator/cmd/machine-remediation-operator/main.go @@ -5,12 +5,17 @@ import ( "runtime" "github.com/golang/glog" + extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + mrv1 "kubevirt.io/machine-remediation-operator/pkg/apis/machineremediation/v1alpha1" + "kubevirt.io/machine-remediation-operator/pkg/consts" "kubevirt.io/machine-remediation-operator/pkg/controllers" "kubevirt.io/machine-remediation-operator/pkg/operator" "kubevirt.io/machine-remediation-operator/pkg/version" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client/config" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/runtime/signals" @@ -34,11 +39,14 @@ func main() { glog.Fatal(err) } - opts := manager.Options{} + namespaces := []string{consts.NamespaceOpenshiftMachineAPI, metav1.NamespaceNone} if *namespace != "" { - opts.Namespace = *namespace - glog.Infof("Watching MRO objects only in namespace %q for reconciliation.", opts.Namespace) + namespaces = append(namespaces, *namespace) } + opts := manager.Options{ + NewCache: cache.MultiNamespacedCacheBuilder(namespaces), + } + // Create a new Cmd to provide shared dependencies and start components mgr, err := manager.New(cfg, opts) if err != nil { diff --git a/vendor/kubevirt.io/machine-remediation-operator/doc.go b/vendor/kubevirt.io/machine-remediation-operator/doc.go new file mode 100644 index 0000000000..e26d0b0588 --- /dev/null +++ b/vendor/kubevirt.io/machine-remediation-operator/doc.go @@ -0,0 +1,21 @@ +/* + * This file is part of the KubeVirt project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2019 Red Hat, Inc. + * + */ +package root + +// This file only exists for the "dep" dependency manager, which needs a go file on the project root diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/consts/consts.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/consts/consts.go index e629e9854b..0eb7a0ab31 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/consts/consts.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/consts/consts.go @@ -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" ) diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/controllers/machinehealthcheck/machinehealthcheck_controller.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/controllers/machinehealthcheck/machinehealthcheck_controller.go index 506bc284c3..0bf6a98704 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -3,6 +3,7 @@ package machinehealthcheck import ( "context" golangerrors "errors" + "fmt" "time" "github.com/golang/glog" @@ -33,14 +34,17 @@ const ( disableRemediationAnotationKey = "healthchecking.openshift.io/disabled" ) +var _ reconcile.Reconciler = &ReconcileMachineHealthCheck{} + // Add creates a new MachineHealthCheck Controller and adds it to the Manager. The Manager will set fields on the Controller // and start it when the Manager is started. func Add(mgr manager.Manager, opts manager.Options) error { - return add(mgr, newReconciler(mgr, opts)) + r := newReconciler(mgr, opts) + return add(mgr, r, r.nodeRequestsFromMachineHealthCheck) } // newReconciler returns a new reconcile.Reconciler -func newReconciler(mgr manager.Manager, opts manager.Options) reconcile.Reconciler { +func newReconciler(mgr manager.Manager, opts manager.Options) *ReconcileMachineHealthCheck { return &ReconcileMachineHealthCheck{ client: mgr.GetClient(), namespace: opts.Namespace, @@ -48,16 +52,90 @@ func newReconciler(mgr manager.Manager, opts manager.Options) reconcile.Reconcil } // add adds a new Controller to mgr with r as the reconcile.Reconciler -func add(mgr manager.Manager, r reconcile.Reconciler) error { +func add(mgr manager.Manager, r reconcile.Reconciler, mapFn handler.ToRequestsFunc) error { // Create a new controller c, err := controller.New("machinehealthcheck-controller", mgr, controller.Options{Reconciler: r}) if err != nil { return err } + + // Watch MachineHealthChecks and enqueue reconcile.Request for the backed nodes. + // This is useful to trigger remediation when a machineHealCheck is created against + // a node which is already unhealthy and is not able to receive status updates. + err = c.Watch(&source.Kind{Type: &mrv1.MachineHealthCheck{}}, &handler.EnqueueRequestsFromMapFunc{ToRequests: mapFn}) + if err != nil { + return err + } + return c.Watch(&source.Kind{Type: &corev1.Node{}}, &handler.EnqueueRequestForObject{}) } -var _ reconcile.Reconciler = &ReconcileMachineHealthCheck{} +func (r *ReconcileMachineHealthCheck) nodeRequestsFromMachineHealthCheck(o handler.MapObject) []reconcile.Request { + glog.V(3).Infof("Watched machineHealthCheck event, finding nodes to reconcile.Request...") + key := client.ObjectKey{ + Namespace: o.Meta.GetNamespace(), + Name: o.Meta.GetName(), + } + mhc := &mrv1.MachineHealthCheck{} + if err := r.client.Get(context.Background(), key, mhc); err != nil { + glog.Errorf("No-op: Unable to retrieve mhc %s/%s from store: %v", o.Meta.GetNamespace(), o.Meta.GetName(), err) + return nil + } + + if mhc.DeletionTimestamp != nil { + glog.V(3).Infof("No-op: mhc %q is being deleted", o.Meta.GetName()) + return nil + } + + // get nodes covered by then mhc + nodeNames, err := r.getNodeNamesForMHC(mhc) + if err != nil { + glog.Errorf("No-op: failed to get nodes for mhc %q", o.Meta.GetName()) + return nil + } + + if nodeNames != nil { + var requests []reconcile.Request + for _, nodeName := range nodeNames { + // convert to namespacedName to satisfy type Request struct + nodeNamespacedName := client.ObjectKey{Name: string(nodeName)} + requests = append(requests, reconcile.Request{NamespacedName: nodeNamespacedName}) + } + return requests + } + return nil +} + +func (r *ReconcileMachineHealthCheck) getNodeNamesForMHC(mhc *mrv1.MachineHealthCheck) ([]types.NodeName, error) { + machineList := &mapiv1.MachineList{} + selector, err := metav1.LabelSelectorAsSelector(&mhc.Spec.Selector) + if err != nil { + return nil, fmt.Errorf("failed to build selector") + } + options := &client.ListOptions{ + Namespace: mhc.Namespace, + LabelSelector: selector, + } + + if err := r.client.List(context.Background(), machineList, client.UseListOptions(options)); err != nil { + return nil, fmt.Errorf("failed to list machines: %v", err) + } + + if len(machineList.Items) < 1 { + return nil, nil + } + + var nodeNames []types.NodeName + for _, machine := range machineList.Items { + if machine.Status.NodeRef != nil { + nodeNames = append(nodeNames, types.NodeName(machine.Status.NodeRef.Name)) + } + } + if len(nodeNames) < 1 { + return nil, nil + } + return nodeNames, nil +} // ReconcileMachineHealthCheck reconciles a MachineHealthCheck object type ReconcileMachineHealthCheck struct { diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/csv.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/csv.go index ab69a91633..05f75f6649 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/csv.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/csv.go @@ -94,7 +94,7 @@ func NewClusterServiceVersion(data *ClusterServiceVersionData) (*csvv1.ClusterSe return nil, err } - csvVersion, err := semver.Make(data.CSVVersion) + csvVersion, err := semver.New(data.CSVVersion) if err != nil { return nil, err } @@ -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{Version: csvVersion}, + Version: version.OperatorVersion{Version: *csvVersion}, Maturity: "alpha", Maintainers: []csvv1.Maintainer{{ Name: "KubeVirt project", diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/deployments.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/deployments.go index 3ad0f5246e..1efa5c661a 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/deployments.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/deployments.go @@ -93,18 +93,21 @@ func newPodTemplateSpec(data *DeploymentData) *corev1.PodTemplateSpec { Spec: corev1.PodSpec{ Affinity: &corev1.Affinity{ PodAntiAffinity: &corev1.PodAntiAffinity{ - RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{ + PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{ { - LabelSelector: &metav1.LabelSelector{ - MatchExpressions: []metav1.LabelSelectorRequirement{ - { - Key: mrv1.SchemeGroupVersion.Group, - Operator: metav1.LabelSelectorOpIn, - Values: []string{data.Name}, + Weight: 50, + PodAffinityTerm: corev1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchExpressions: []metav1.LabelSelectorRequirement{ + { + Key: mrv1.SchemeGroupVersion.Group, + Operator: metav1.LabelSelectorOpIn, + Values: []string{data.Name}, + }, }, }, + TopologyKey: "kubernetes.io/hostname", }, - TopologyKey: "kubernetes.io/hostname", }, }, }, diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/rbac.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/rbac.go index 4ec598d898..d918bc9c0d 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/rbac.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/components/rbac.go @@ -261,6 +261,19 @@ var ( "watch", }, }, + { + APIGroups: []string{ + "", + }, + Resources: []string{ + "nodes", + }, + Verbs: []string{ + "get", + "list", + "watch", + }, + }, { APIGroups: []string{ "", diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/resources.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/resources.go index 670af0507b..d43ebdd634 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/resources.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/operator/resources.go @@ -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) { @@ -48,7 +51,12 @@ func (r *ReconcileMachineRemediationOperator) createOrUpdateDeployment(data *com } newDeploy := components.NewDeployment(data) - newDeploy.Spec.Replicas = pointer.Int32Ptr(2) + + 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) { @@ -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 { diff --git a/vendor/kubevirt.io/machine-remediation-operator/pkg/utils/testing/testing.go b/vendor/kubevirt.io/machine-remediation-operator/pkg/utils/testing/testing.go index 359eca69c8..6a9dc95bd0 100644 --- a/vendor/kubevirt.io/machine-remediation-operator/pkg/utils/testing/testing.go +++ b/vendor/kubevirt.io/machine-remediation-operator/pkg/utils/testing/testing.go @@ -117,7 +117,7 @@ func NewBareMetalHost(name string, online bool, powerOn bool) *bmov1.BareMetalHo // NewMachine returns new machine object that can be used for testing func NewMachine(name string, nodeName string, bareMetalHostName string) *mapiv1.Machine { - return &mapiv1.Machine{ + m := &mapiv1.Machine{ TypeMeta: metav1.TypeMeta{Kind: "Machine"}, ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ @@ -129,13 +129,16 @@ func NewMachine(name string, nodeName string, bareMetalHostName string) *mapiv1. Labels: FooBar(), }, Spec: mapiv1.MachineSpec{}, - Status: mapiv1.MachineStatus{ + } + if nodeName != "" { + m.Status = mapiv1.MachineStatus{ NodeRef: &corev1.ObjectReference{ Name: nodeName, Namespace: metav1.NamespaceNone, }, - }, + } } + return m } // NewMachineRemediation returns new machine remediation object that can be used for testing