Clean up scheduling/v1alpha1 types for kubebuilder
/*
-Copyright 2018 The Federation v2 Authors.
+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.
@@ -17,31 +17,9 @@ limitations under the License.
package v1alpha1
import (
- "log"
-
- "k8s.io/apimachinery/pkg/runtime"
- "k8s.io/apiserver/pkg/endpoints/request"
-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/util/validation/field"
-
- "github.com/kubernetes-sigs/federation-v2/pkg/apis/federatedscheduling"
)
-// +genclient
-// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
-
-// ReplicaSchedulingPreference
-// +k8s:openapi-gen=true
-// +resource:path=replicaschedulingpreferences,strategy=ReplicaSchedulingPreferenceStrategy
-type ReplicaSchedulingPreference struct {
- metav1.TypeMeta `json:",inline"`
- metav1.ObjectMeta `json:"metadata,omitempty"`
-
- Spec ReplicaSchedulingPreferenceSpec `json:"spec,omitempty"`
- Status ReplicaSchedulingPreferenceStatus `json:"status,omitempty"`
-}
-
// ReplicaSchedulingPreferenceSpec defines the desired state of ReplicaSchedulingPreference
type ReplicaSchedulingPreferenceSpec struct {
//TODO (@irfanurrehman); upgrade this to label selector only if need be.
@@ -96,30 +74,16 @@ type ClusterPreferences struct {
type ReplicaSchedulingPreferenceStatus struct {
}
-// Validate checks that an instance of ReplicaSchedulingPreference is well formed
-func (ReplicaSchedulingPreferenceStrategy) Validate(ctx request.Context, obj runtime.Object) field.ErrorList {
- o := obj.(*federatedscheduling.ReplicaSchedulingPreference)
- log.Printf("Validating fields for ReplicaSchedulingPreference %s\n", o.Name)
- errors := field.ErrorList{}
- if o.Spec.TotalReplicas < 1 {
- errors = append(errors, field.Invalid(field.NewPath("replicaschedulingpreference").Child("totalreplicas"), o.Spec.TotalReplicas, ""))
- }
-
- if len(o.Spec.TargetKind) == 0 {
- errors = append(errors, field.Required(field.NewPath("replicaschedulingpreference").Child("spec").Child("kind"), "targetKind is required"))
- }
-
- if o.Spec.TargetKind != "FederatedDeployment" && o.Spec.TargetKind != "FederatedReplicaSet" {
- errors = append(errors, field.Invalid(field.NewPath("replicaschedulingpreference").Child("spec").Child("kind"), o.Spec.TargetKind, "TargetKind accepts kinds: FederatedDeployment/FederatedReplicaSet"))
- }
+// +genclient
+// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
- // perform validation here and add to errors using field.Invalid
- return errors
-}
+// ReplicaSchedulingPreference
+// +k8s:openapi-gen=true
+// +kubebuilder:resource:path=replicaschedulingpreferences
+type ReplicaSchedulingPreference struct {
+ metav1.TypeMeta `json:",inline"`
+ metav1.ObjectMeta `json:"metadata,omitempty"`
-// DefaultingFunction sets default ReplicaSchedulingPreference field values
-func (ReplicaSchedulingPreferenceSchemeFns) DefaultingFunction(o interface{}) {
- obj := o.(*ReplicaSchedulingPreference)
- // set default field values here
- log.Printf("Defaulting fields for ReplicaSchedulingPreference %s\n", obj.Name)
+ Spec ReplicaSchedulingPreferenceSpec `json:"spec,omitempty"`
+ Status ReplicaSchedulingPreferenceStatus `json:"status,omitempty"`
}
