Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
detiber committed Nov 20, 2019
1 parent 09d8383 commit f9e545d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 61 deletions.
41 changes: 2 additions & 39 deletions api/v1alpha3/kubeadm_control_plane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion api/v1alpha3/kubeadm_control_plane_webhook_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 0 additions & 15 deletions api/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions config/default/webhookcainjection_patch.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 25 additions & 0 deletions errors/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
30 changes: 30 additions & 0 deletions errors/kubeadmcontrolplane.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f9e545d

Please sign in to comment.