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