diff --git a/Gopkg.lock b/Gopkg.lock index ccfaf0ebc4..8ef4792a82 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -485,7 +485,7 @@ [[projects]] branch = "openshift-4.0-cluster-api-0.0.0-alpha.4" - digest = "1:fdddf352fc7677bb205bc1a84a8c4205c92ca2b1b8cf50e862a7cbbf26da4b10" + digest = "1:6c1953688007e98a582591088bfede8a3bb9e81dce2cdac3b4ace98730f6e2e5" name = "github.com/openshift/cluster-api" packages = [ "pkg/apis", @@ -505,7 +505,7 @@ "pkg/util", ] pruneopts = "T" - revision = "9839db3a35e26b97dccc223fc7b7310e4fb48544" + revision = "f46665c25908ee8fd5cb6506f374e3ae254a08dc" [[projects]] branch = "master" diff --git a/vendor/github.com/openshift/cluster-api-actuator-pkg/pkg/manifests/manifests.go b/vendor/github.com/openshift/cluster-api-actuator-pkg/pkg/manifests/manifests.go index d5ead12d4d..e975c0134a 100644 --- a/vendor/github.com/openshift/cluster-api-actuator-pkg/pkg/manifests/manifests.go +++ b/vendor/github.com/openshift/cluster-api-actuator-pkg/pkg/manifests/manifests.go @@ -948,7 +948,7 @@ func TestingMachine(clusterID string, namespace string, providerSpec machinev1be Namespace: namespace, GenerateName: "vs-master-", Labels: map[string]string{ - "sigs.k8s.io/cluster-api-cluster": clusterID, + "machine.openshift.io/cluster-api-cluster": clusterID, }, }, Spec: machinev1beta1.MachineSpec{ @@ -976,7 +976,7 @@ func MasterMachine(clusterID, namespace string, providerSpec machinev1beta1.Prov Namespace: namespace, GenerateName: "vs-master-", Labels: map[string]string{ - "sigs.k8s.io/cluster-api-cluster": clusterID, + "machine.openshift.io/cluster-api-cluster": clusterID, }, }, Spec: machinev1beta1.MachineSpec{ @@ -1050,14 +1050,14 @@ func WorkerMachineSet(clusterID, namespace string, providerSpec machinev1beta1.P Namespace: namespace, GenerateName: clusterID + "-worker-machine-" + randomUUID[:6] + "-", Labels: map[string]string{ - "sigs.k8s.io/cluster-api-cluster": clusterID, + "machine.openshift.io/cluster-api-cluster": clusterID, }, }, Spec: machinev1beta1.MachineSetSpec{ Selector: metav1.LabelSelector{ MatchLabels: map[string]string{ - "sigs.k8s.io/cluster-api-machineset": clusterID + "-worker-machineset-" + randomUUID[:6], - "sigs.k8s.io/cluster-api-cluster": clusterID, + "sigs.k8s.io/cluster-api-machineset": clusterID + "-worker-machineset-" + randomUUID[:6], + "machine.openshift.io/cluster-api-cluster": clusterID, }, }, Replicas: &replicas, @@ -1065,8 +1065,8 @@ func WorkerMachineSet(clusterID, namespace string, providerSpec machinev1beta1.P ObjectMeta: metav1.ObjectMeta{ GenerateName: clusterID + "-worker-machine-" + randomUUID[:6] + "-", Labels: map[string]string{ - "sigs.k8s.io/cluster-api-machineset": clusterID + "-worker-machineset-" + randomUUID[:6], - "sigs.k8s.io/cluster-api-cluster": clusterID, + "sigs.k8s.io/cluster-api-machineset": clusterID + "-worker-machineset-" + randomUUID[:6], + "machine.openshift.io/cluster-api-cluster": clusterID, }, }, Spec: machinev1beta1.MachineSpec{ diff --git a/vendor/github.com/openshift/cluster-api/pkg/apis/machine/v1beta1/machine_types.go b/vendor/github.com/openshift/cluster-api/pkg/apis/machine/v1beta1/machine_types.go index e7fbb4b7fe..e7a386a8d1 100644 --- a/vendor/github.com/openshift/cluster-api/pkg/apis/machine/v1beta1/machine_types.go +++ b/vendor/github.com/openshift/cluster-api/pkg/apis/machine/v1beta1/machine_types.go @@ -17,9 +17,12 @@ limitations under the License. package v1beta1 import ( + "fmt" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" "github.com/openshift/cluster-api/pkg/apis/machine/common" ) @@ -30,6 +33,10 @@ const ( // MachineClusterLabelName is the label set on machines linked to a cluster. MachineClusterLabelName = "cluster.k8s.io/cluster-name" + + // MachineClusterIDLabel is the label that a machine must have to identify the + // cluster to which it belongs. + MachineClusterIDLabel = "machine.openshift.io/cluster-api-cluster" ) // +genclient @@ -231,6 +238,23 @@ type MachineVersionInfo struct { /// [MachineVersionInfo] +func (m *Machine) Validate() field.ErrorList { + errors := field.ErrorList{} + + // validate spec.labels + fldPath := field.NewPath("spec") + if m.Labels[MachineClusterIDLabel] == "" { + errors = append(errors, field.Invalid(fldPath.Child("labels"), m.Labels, fmt.Sprintf("missing %v label.", MachineClusterIDLabel))) + } + + // validate provider config is set + if m.Spec.ProviderSpec.Value == nil && m.Spec.ProviderSpec.ValueFrom == nil { + errors = append(errors, field.Invalid(fldPath.Child("spec").Child("providerspec"), m.Spec.ProviderSpec, "at least one of value or valueFrom fields must be set")) + } + + return errors +} + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // MachineList contains a list of Machine diff --git a/vendor/github.com/openshift/cluster-api/pkg/controller/machine/controller.go b/vendor/github.com/openshift/cluster-api/pkg/controller/machine/controller.go index c47a6f7434..227793a4dc 100644 --- a/vendor/github.com/openshift/cluster-api/pkg/controller/machine/controller.go +++ b/vendor/github.com/openshift/cluster-api/pkg/controller/machine/controller.go @@ -127,6 +127,13 @@ func (r *ReconcileMachine) Reconcile(request reconcile.Request) (reconcile.Resul name := m.Name klog.Infof("Reconciling Machine %q", name) + if errList := m.Validate(); len(errList) > 0 { + err := fmt.Errorf("%q machine validation failed: %v", m.Name, errList.ToAggregate().Error()) + klog.Error(err) + r.eventRecorder.Eventf(m, corev1.EventTypeWarning, "FailedValidate", err.Error()) + return reconcile.Result{}, err + } + // Cluster might be nil as some providers might not require a cluster object // for machine management. cluster, err := r.getCluster(ctx, m) @@ -178,7 +185,7 @@ func (r *ReconcileMachine) Reconcile(request reconcile.Request) (reconcile.Resul } if !r.isDeleteAllowed(m) { - klog.Infof("Skipping reconciling of machine %q", name) + klog.Infof("Deleting machine hosting this controller is not allowed. Skipping reconciliation of machine %q", name) return reconcile.Result{}, nil }