diff --git a/api/v1alpha3/kubeadm_control_plane_types.go b/api/v1alpha3/kubeadm_control_plane_types.go index 9c03386ef285..d17d3965cd4f 100644 --- a/api/v1alpha3/kubeadm_control_plane_types.go +++ b/api/v1alpha3/kubeadm_control_plane_types.go @@ -20,6 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha2" + "sigs.k8s.io/cluster-api/errors" ) // KubeadmControlPlaneSpec defines the desired state of KubeadmControlPlane. @@ -89,7 +90,7 @@ type KubeadmControlPlaneStatus struct { // state, and will be set to a token value suitable for // programmatic interpretation. // +optional - FailureReason KubeadmControlPlaneStatusError `json:"failureReason,omitempty"` + Failurereason errors.KubeadmControlPlaneStatusError `json:"failureReason,omitempty"` // ErrorMessage indicates that there is a terminal problem reconciling the // state, and will be set to a descriptive error message. @@ -124,41 +125,3 @@ type KubeadmControlPlaneList struct { func init() { SchemeBuilder.Register(&KubeadmControlPlane{}, &KubeadmControlPlaneList{}) } - -type KubeadmControlPlaneStatusError string - -// A more descriptive kind of error that represents an error condition that -// should be set in the KubeadmControlPlane.Status. The "Reason" field is meant for short, -// enum-style constants meant to be interpreted by control planes. The "Message" -// field is meant to be read by humans. -type KubeadmControlPlaneError struct { - Reason KubeadmControlPlaneStatusError - Message string -} - -func (e *KubeadmControlPlaneError) Error() string { - return e.Message -} - -const ( - // InvalidConfigurationKubeadmControlPlaneError indicates that the kubeadm control plane - // configuration is invalid. - InvalidConfigurationKubeadmControlPlaneError KubeadmControlPlaneStatusError = "InvalidConfiguration" - - // UnsupportedChangeKubeadmControlPlaneError indicates that the kubeadm control plane - // spec has been updated in an unsupported way. That cannot be - // reconciled. - UnsupportedChangeKubeadmControlPlaneError KubeadmControlPlaneStatusError = "UnsupportedChange" - - // CreateKubeadmControlPlaneError indicates that an error was encountered - // when trying to create the kubeadm control plane. - CreateKubeadmControlPlaneError KubeadmControlPlaneStatusError = "CreateError" - - // UpdateKubeadmControlPlaneError indicates that an error was encountered - // when trying to update the kubeadm control plane. - UpdateKubeadmControlPlaneError KubeadmControlPlaneStatusError = "UpdateError" - - // DeleteKubeadmControlPlaneError indicates that an error was encountered - // when trying to delete the kubeadm control plane. - DeleteKubeadmControlPlaneError KubeadmControlPlaneStatusError = "DeleteError" -) diff --git a/api/v1alpha3/kubeadm_control_plane_webhook_validation.go b/api/v1alpha3/kubeadm_control_plane_webhook_validation.go index 324dab78b562..992f84d74efe 100644 --- a/api/v1alpha3/kubeadm_control_plane_webhook_validation.go +++ b/api/v1alpha3/kubeadm_control_plane_webhook_validation.go @@ -38,7 +38,7 @@ var _ webhook.Validator = &KubeadmControlPlane{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type func (r *KubeadmControlPlane) ValidateCreate() error { if r.Spec.Replicas == nil { - return field.Forbidden(field.NewPath("spec", "replicas"), "cannot be nil") + return field.Required(field.NewPath("spec", "replicas"), "is required") } if *r.Spec.Replicas <= 0 { diff --git a/api/v1alpha3/zz_generated.deepcopy.go b/api/v1alpha3/zz_generated.deepcopy.go index ba4e6a2d6464..80539397d2bb 100644 --- a/api/v1alpha3/zz_generated.deepcopy.go +++ b/api/v1alpha3/zz_generated.deepcopy.go @@ -239,21 +239,6 @@ func (in *KubeadmControlPlane) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *KubeadmControlPlaneError) DeepCopyInto(out *KubeadmControlPlaneError) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubeadmControlPlaneError. -func (in *KubeadmControlPlaneError) DeepCopy() *KubeadmControlPlaneError { - if in == nil { - return nil - } - out := new(KubeadmControlPlaneError) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KubeadmControlPlaneList) DeepCopyInto(out *KubeadmControlPlaneList) { *out = *in diff --git a/config/default/webhookcainjection_patch.yaml b/config/default/webhookcainjection_patch.yaml index dde99153707a..b114287923d4 100644 --- a/config/default/webhookcainjection_patch.yaml +++ b/config/default/webhookcainjection_patch.yaml @@ -1,12 +1,12 @@ # This patch add annotation to admission webhook config and # the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. # uncomment the following lines to enable mutating webhook -#apiVersion: admissionregistration.k8s.io/v1beta1 -#kind: MutatingWebhookConfiguration -#metadata: -# name: mutating-webhook-configuration -# annotations: -# cert-manager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) +apiVersion: admissionregistration.k8s.io/v1beta1 +kind: MutatingWebhookConfiguration +metadata: + name: mutating-webhook-configuration + annotations: + cert-manager.k8s.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) --- apiVersion: admissionregistration.k8s.io/v1beta1 kind: ValidatingWebhookConfiguration diff --git a/errors/consts.go b/errors/consts.go index de94f507a409..558a2797aed4 100644 --- a/errors/consts.go +++ b/errors/consts.go @@ -111,3 +111,28 @@ const ( // Example: the ProviderSpec specifies an instance type that doesn't exist. InvalidConfigurationMachineSetError MachineSetStatusError = "InvalidConfiguration" ) + +type KubeadmControlPlaneStatusError string + +const ( + // InvalidConfigurationKubeadmControlPlaneError indicates that the kubeadm control plane + // configuration is invalid. + InvalidConfigurationKubeadmControlPlaneError KubeadmControlPlaneStatusError = "InvalidConfiguration" + + // UnsupportedChangeKubeadmControlPlaneError indicates that the kubeadm control plane + // spec has been updated in an unsupported way that cannot be + // reconciled. + UnsupportedChangeKubeadmControlPlaneError KubeadmControlPlaneStatusError = "UnsupportedChange" + + // CreateKubeadmControlPlaneError indicates that an error was encountered + // when trying to create the kubeadm control plane. + CreateKubeadmControlPlaneError KubeadmControlPlaneStatusError = "CreateError" + + // UpdateKubeadmControlPlaneError indicates that an error was encountered + // when trying to update the kubeadm control plane. + UpdateKubeadmControlPlaneError KubeadmControlPlaneStatusError = "UpdateError" + + // DeleteKubeadmControlPlaneError indicates that an error was encountered + // when trying to delete the kubeadm control plane. + DeleteKubeadmControlPlaneError KubeadmControlPlaneStatusError = "DeleteError" +) diff --git a/errors/kubeadmcontrolplane.go b/errors/kubeadmcontrolplane.go new file mode 100644 index 000000000000..f45accdcc271 --- /dev/null +++ b/errors/kubeadmcontrolplane.go @@ -0,0 +1,30 @@ +/* +Copyright 2018 The Kubernetes Authors. + +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. +*/ + +package errors + +// KubeadmControlPlaneError is a more descriptive kind of error that represents an error condition that +// should be set in the KubeadmControlPlane.Status. The "Reason" field is meant for short, +// enum-style constants meant to be interpreted by control planes. The "Message" +// field is meant to be read by humans. +type KubeadmControlPlaneError struct { + Reason KubeadmControlPlaneStatusError + Message string +} + +func (e *KubeadmControlPlaneError) Error() string { + return e.Message +}