mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Fix golint issues in pkg/apis/apps and pkg/apis/apps/validation
This commit is contained in:
parent
5713c22eec
commit
905e7510c8
@ -10,7 +10,6 @@ pkg/apis/apps
|
|||||||
pkg/apis/apps/v1
|
pkg/apis/apps/v1
|
||||||
pkg/apis/apps/v1beta1
|
pkg/apis/apps/v1beta1
|
||||||
pkg/apis/apps/v1beta2
|
pkg/apis/apps/v1beta2
|
||||||
pkg/apis/apps/validation
|
|
||||||
pkg/apis/auditregistration/v1alpha1
|
pkg/apis/auditregistration/v1alpha1
|
||||||
pkg/apis/authentication/v1
|
pkg/apis/authentication/v1
|
||||||
pkg/apis/authorization/v1
|
pkg/apis/authorization/v1
|
||||||
|
@ -23,8 +23,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// SchemeBuilder stores functions to add things to a scheme.
|
||||||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
||||||
AddToScheme = SchemeBuilder.AddToScheme
|
// AddToScheme applies all stored functions t oa scheme.
|
||||||
|
AddToScheme = SchemeBuilder.AddToScheme
|
||||||
)
|
)
|
||||||
|
|
||||||
// GroupName is the group name use in this package
|
// GroupName is the group name use in this package
|
||||||
|
@ -198,6 +198,7 @@ type StatefulSetStatus struct {
|
|||||||
Conditions []StatefulSetCondition
|
Conditions []StatefulSetCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatefulSetConditionType describes the condition types of StatefulSets.
|
||||||
type StatefulSetConditionType string
|
type StatefulSetConditionType string
|
||||||
|
|
||||||
// TODO: Add valid condition types for Statefulsets.
|
// TODO: Add valid condition types for Statefulsets.
|
||||||
@ -262,6 +263,7 @@ type ControllerRevisionList struct {
|
|||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
|
||||||
|
// Deployment provides declarative updates for Pods and ReplicaSets.
|
||||||
type Deployment struct {
|
type Deployment struct {
|
||||||
metav1.TypeMeta
|
metav1.TypeMeta
|
||||||
// +optional
|
// +optional
|
||||||
@ -276,6 +278,7 @@ type Deployment struct {
|
|||||||
Status DeploymentStatus
|
Status DeploymentStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeploymentSpec specifies the state of a Deployment.
|
||||||
type DeploymentSpec struct {
|
type DeploymentSpec struct {
|
||||||
// Number of desired pods. This is a pointer to distinguish between explicit
|
// Number of desired pods. This is a pointer to distinguish between explicit
|
||||||
// zero and not specified. Defaults to 1.
|
// zero and not specified. Defaults to 1.
|
||||||
@ -342,6 +345,7 @@ type DeploymentRollback struct {
|
|||||||
RollbackTo RollbackConfig
|
RollbackTo RollbackConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RollbackConfig specifies the state of a revision to roll back to.
|
||||||
// DEPRECATED.
|
// DEPRECATED.
|
||||||
type RollbackConfig struct {
|
type RollbackConfig struct {
|
||||||
// The revision to rollback to. If set to 0, rollback to the last revision.
|
// The revision to rollback to. If set to 0, rollback to the last revision.
|
||||||
@ -356,6 +360,8 @@ const (
|
|||||||
DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
|
DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DeploymentStrategy stores information about the strategy and rolling-update
|
||||||
|
// behavior of a deployment.
|
||||||
type DeploymentStrategy struct {
|
type DeploymentStrategy struct {
|
||||||
// Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate.
|
// Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate.
|
||||||
// +optional
|
// +optional
|
||||||
@ -370,6 +376,7 @@ type DeploymentStrategy struct {
|
|||||||
RollingUpdate *RollingUpdateDeployment
|
RollingUpdate *RollingUpdateDeployment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeploymentStrategyType defines strategies with a deployment.
|
||||||
type DeploymentStrategyType string
|
type DeploymentStrategyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -409,6 +416,7 @@ type RollingUpdateDeployment struct {
|
|||||||
MaxSurge intstr.IntOrString
|
MaxSurge intstr.IntOrString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeploymentStatus holds information about the observed status of a deployment.
|
||||||
type DeploymentStatus struct {
|
type DeploymentStatus struct {
|
||||||
// The generation observed by the deployment controller.
|
// The generation observed by the deployment controller.
|
||||||
// +optional
|
// +optional
|
||||||
@ -446,6 +454,7 @@ type DeploymentStatus struct {
|
|||||||
CollisionCount *int32
|
CollisionCount *int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeploymentConditionType defines conditions of a deployment.
|
||||||
type DeploymentConditionType string
|
type DeploymentConditionType string
|
||||||
|
|
||||||
// These are valid conditions of a deployment.
|
// These are valid conditions of a deployment.
|
||||||
@ -481,6 +490,7 @@ type DeploymentCondition struct {
|
|||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
|
||||||
|
// DeploymentList defines multiple deployments.
|
||||||
type DeploymentList struct {
|
type DeploymentList struct {
|
||||||
metav1.TypeMeta
|
metav1.TypeMeta
|
||||||
// +optional
|
// +optional
|
||||||
@ -490,6 +500,7 @@ type DeploymentList struct {
|
|||||||
Items []Deployment
|
Items []Deployment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DaemonSetUpdateStrategy defines a strategy to update a daemon set.
|
||||||
type DaemonSetUpdateStrategy struct {
|
type DaemonSetUpdateStrategy struct {
|
||||||
// Type of daemon set update. Can be "RollingUpdate" or "OnDelete".
|
// Type of daemon set update. Can be "RollingUpdate" or "OnDelete".
|
||||||
// Default is OnDelete.
|
// Default is OnDelete.
|
||||||
@ -505,6 +516,8 @@ type DaemonSetUpdateStrategy struct {
|
|||||||
RollingUpdate *RollingUpdateDaemonSet
|
RollingUpdate *RollingUpdateDaemonSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DaemonSetUpdateStrategyType is a strategy according to which a daemon set
|
||||||
|
// gets updated.
|
||||||
type DaemonSetUpdateStrategyType string
|
type DaemonSetUpdateStrategyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -623,6 +636,7 @@ type DaemonSetStatus struct {
|
|||||||
Conditions []DaemonSetCondition
|
Conditions []DaemonSetCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DaemonSetConditionType defines a daemon set condition.
|
||||||
type DaemonSetConditionType string
|
type DaemonSetConditionType string
|
||||||
|
|
||||||
// TODO: Add valid condition types of a DaemonSet.
|
// TODO: Add valid condition types of a DaemonSet.
|
||||||
@ -768,6 +782,7 @@ type ReplicaSetStatus struct {
|
|||||||
Conditions []ReplicaSetCondition
|
Conditions []ReplicaSetCondition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReplicaSetConditionType is a condition of a replica set.
|
||||||
type ReplicaSetConditionType string
|
type ReplicaSetConditionType string
|
||||||
|
|
||||||
// These are valid conditions of a replica set.
|
// These are valid conditions of a replica set.
|
||||||
|
@ -255,6 +255,7 @@ func ValidateDaemonSetUpdate(ds, oldDS *apps.DaemonSet) field.ErrorList {
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDaemonSetSpecUpdate tests if an update to a DaemonSetSpec is valid.
|
||||||
func ValidateDaemonSetSpecUpdate(newSpec, oldSpec *apps.DaemonSetSpec, fldPath *field.Path) field.ErrorList {
|
func ValidateDaemonSetSpecUpdate(newSpec, oldSpec *apps.DaemonSetSpec, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
@ -291,7 +292,7 @@ func validateDaemonSetStatus(status *apps.DaemonSetStatus, fldPath *field.Path)
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateDaemonSetStatusUpdate validates tests if required fields in the DaemonSet Status section
|
// ValidateDaemonSetStatusUpdate tests if required fields in the DaemonSet Status section
|
||||||
func ValidateDaemonSetStatusUpdate(ds, oldDS *apps.DaemonSet) field.ErrorList {
|
func ValidateDaemonSetStatusUpdate(ds, oldDS *apps.DaemonSet) field.ErrorList {
|
||||||
allErrs := apivalidation.ValidateObjectMetaUpdate(&ds.ObjectMeta, &oldDS.ObjectMeta, field.NewPath("metadata"))
|
allErrs := apivalidation.ValidateObjectMetaUpdate(&ds.ObjectMeta, &oldDS.ObjectMeta, field.NewPath("metadata"))
|
||||||
allErrs = append(allErrs, validateDaemonSetStatus(&ds.Status, field.NewPath("status"))...)
|
allErrs = append(allErrs, validateDaemonSetStatus(&ds.Status, field.NewPath("status"))...)
|
||||||
@ -340,6 +341,7 @@ func ValidateDaemonSetSpec(spec *apps.DaemonSetSpec, fldPath *field.Path) field.
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateRollingUpdateDaemonSet validates a given RollingUpdateDaemonSet.
|
||||||
func ValidateRollingUpdateDaemonSet(rollingUpdate *apps.RollingUpdateDaemonSet, fldPath *field.Path) field.ErrorList {
|
func ValidateRollingUpdateDaemonSet(rollingUpdate *apps.RollingUpdateDaemonSet, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fldPath.Child("maxUnavailable"))...)
|
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fldPath.Child("maxUnavailable"))...)
|
||||||
@ -352,6 +354,7 @@ func ValidateRollingUpdateDaemonSet(rollingUpdate *apps.RollingUpdateDaemonSet,
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDaemonSetUpdateStrategy validates a given DaemonSetUpdateStrategy.
|
||||||
func ValidateDaemonSetUpdateStrategy(strategy *apps.DaemonSetUpdateStrategy, fldPath *field.Path) field.ErrorList {
|
func ValidateDaemonSetUpdateStrategy(strategy *apps.DaemonSetUpdateStrategy, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
switch strategy.Type {
|
switch strategy.Type {
|
||||||
@ -378,6 +381,8 @@ var ValidateDaemonSetName = apimachineryvalidation.NameIsDNSSubdomain
|
|||||||
// ValidateDeploymentName validates that the given name can be used as a deployment name.
|
// ValidateDeploymentName validates that the given name can be used as a deployment name.
|
||||||
var ValidateDeploymentName = apimachineryvalidation.NameIsDNSSubdomain
|
var ValidateDeploymentName = apimachineryvalidation.NameIsDNSSubdomain
|
||||||
|
|
||||||
|
// ValidatePositiveIntOrPercent tests if a given value is a valid int or
|
||||||
|
// percentage.
|
||||||
func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fldPath *field.Path) field.ErrorList {
|
func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
switch intOrPercent.Type {
|
switch intOrPercent.Type {
|
||||||
@ -412,6 +417,8 @@ func getIntOrPercentValue(intOrStringValue intstr.IntOrString) int {
|
|||||||
return intOrStringValue.IntValue()
|
return intOrStringValue.IntValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNotMoreThan100Percent tests is a value can be represented as a percentage
|
||||||
|
// and if this value is not more than 100%.
|
||||||
func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fldPath *field.Path) field.ErrorList {
|
func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
value, isPercent := getPercentValue(intOrStringValue)
|
value, isPercent := getPercentValue(intOrStringValue)
|
||||||
@ -422,6 +429,7 @@ func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fldPath *field
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateRollingUpdateDeployment validates a given RollingUpdateDeployment.
|
||||||
func ValidateRollingUpdateDeployment(rollingUpdate *apps.RollingUpdateDeployment, fldPath *field.Path) field.ErrorList {
|
func ValidateRollingUpdateDeployment(rollingUpdate *apps.RollingUpdateDeployment, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fldPath.Child("maxUnavailable"))...)
|
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fldPath.Child("maxUnavailable"))...)
|
||||||
@ -435,6 +443,7 @@ func ValidateRollingUpdateDeployment(rollingUpdate *apps.RollingUpdateDeployment
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDeploymentStrategy validates given DeploymentStrategy.
|
||||||
func ValidateDeploymentStrategy(strategy *apps.DeploymentStrategy, fldPath *field.Path) field.ErrorList {
|
func ValidateDeploymentStrategy(strategy *apps.DeploymentStrategy, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
switch strategy.Type {
|
switch strategy.Type {
|
||||||
@ -456,6 +465,7 @@ func ValidateDeploymentStrategy(strategy *apps.DeploymentStrategy, fldPath *fiel
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateRollback validates given RollbackConfig.
|
||||||
func ValidateRollback(rollback *apps.RollbackConfig, fldPath *field.Path) field.ErrorList {
|
func ValidateRollback(rollback *apps.RollbackConfig, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
v := rollback.Revision
|
v := rollback.Revision
|
||||||
@ -530,12 +540,15 @@ func ValidateDeploymentStatus(status *apps.DeploymentStatus, fldPath *field.Path
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDeploymentUpdate tests if an update to a Deployment is valid.
|
||||||
func ValidateDeploymentUpdate(update, old *apps.Deployment) field.ErrorList {
|
func ValidateDeploymentUpdate(update, old *apps.Deployment) field.ErrorList {
|
||||||
allErrs := apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))
|
allErrs := apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))
|
||||||
allErrs = append(allErrs, ValidateDeploymentSpec(&update.Spec, field.NewPath("spec"))...)
|
allErrs = append(allErrs, ValidateDeploymentSpec(&update.Spec, field.NewPath("spec"))...)
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDeploymentStatusUpdate tests if a an update to a Deployment status
|
||||||
|
// is valid.
|
||||||
func ValidateDeploymentStatusUpdate(update, old *apps.Deployment) field.ErrorList {
|
func ValidateDeploymentStatusUpdate(update, old *apps.Deployment) field.ErrorList {
|
||||||
allErrs := apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))
|
allErrs := apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta, field.NewPath("metadata"))
|
||||||
fldPath := field.NewPath("status")
|
fldPath := field.NewPath("status")
|
||||||
@ -550,12 +563,14 @@ func ValidateDeploymentStatusUpdate(update, old *apps.Deployment) field.ErrorLis
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDeployment validates a given Deployment.
|
||||||
func ValidateDeployment(obj *apps.Deployment) field.ErrorList {
|
func ValidateDeployment(obj *apps.Deployment) field.ErrorList {
|
||||||
allErrs := apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateDeploymentName, field.NewPath("metadata"))
|
allErrs := apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateDeploymentName, field.NewPath("metadata"))
|
||||||
allErrs = append(allErrs, ValidateDeploymentSpec(&obj.Spec, field.NewPath("spec"))...)
|
allErrs = append(allErrs, ValidateDeploymentSpec(&obj.Spec, field.NewPath("spec"))...)
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateDeploymentRollback validates a given DeploymentRollback.
|
||||||
func ValidateDeploymentRollback(obj *apps.DeploymentRollback) field.ErrorList {
|
func ValidateDeploymentRollback(obj *apps.DeploymentRollback) field.ErrorList {
|
||||||
allErrs := apivalidation.ValidateAnnotations(obj.UpdatedAnnotations, field.NewPath("updatedAnnotations"))
|
allErrs := apivalidation.ValidateAnnotations(obj.UpdatedAnnotations, field.NewPath("updatedAnnotations"))
|
||||||
if len(obj.Name) == 0 {
|
if len(obj.Name) == 0 {
|
||||||
@ -594,6 +609,7 @@ func ValidateReplicaSetStatusUpdate(rs, oldRs *apps.ReplicaSet) field.ErrorList
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateReplicaSetStatus validates a given ReplicaSetStatus.
|
||||||
func ValidateReplicaSetStatus(status apps.ReplicaSetStatus, fldPath *field.Path) field.ErrorList {
|
func ValidateReplicaSetStatus(status apps.ReplicaSetStatus, fldPath *field.Path) field.ErrorList {
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.Replicas), fldPath.Child("replicas"))...)
|
allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(status.Replicas), fldPath.Child("replicas"))...)
|
||||||
|
Loading…
Reference in New Issue
Block a user