Skip to content

Commit

Permalink
return Forbidden is appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: 李龙峰 <[email protected]>
  • Loading branch information
李龙峰 committed Nov 25, 2023
1 parent 15bd83b commit 34837d6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cmd/yurt-manager/app/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ current state towards the desired state.`,
return cmd
}

// PrintFlags logs the flags in the flagset
// PrintFlags logs the flags in the flagSet
func PrintFlags(flags *pflag.FlagSet) {
flags.VisitAll(func(flag *pflag.Flag) {
klog.V(1).Infof("FLAG: --%s=%q", flag.Name, flag.Value)
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/gatewaycontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ func NewGatewayPickupControllerOptions() *GatewayPickupControllerOptions {
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (g *GatewayPickupControllerOptions) AddFlags(fs *pflag.FlagSet) {
if g == nil {
return
}

}

// ApplyTo fills up nodepool config with options.
// ApplyTo fills up nodePool config with options.
func (g *GatewayPickupControllerOptions) ApplyTo(cfg *config.GatewayPickupControllerConfiguration) error {
if g == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/nodepoolcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewNodePoolControllerOptions() *NodePoolControllerOptions {
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (n *NodePoolControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
Expand All @@ -43,7 +43,7 @@ func (n *NodePoolControllerOptions) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&n.EnableSyncNodePoolConfigurations, "enable-sync-nodepool-configurations", n.EnableSyncNodePoolConfigurations, "enable to sync nodepool configurations(including labels, annotations, taints in spec) to nodes in the nodepool.")
}

// ApplyTo fills up nodepool config with options.
// ApplyTo fills up nodePool config with options.
func (o *NodePoolControllerOptions) ApplyTo(cfg *config.NodePoolControllerConfiguration) error {
if o == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/platformadmincontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func NewPlatformAdminControllerOptions() *PlatformAdminControllerOptions {
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (n *PlatformAdminControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
}
}

// ApplyTo fills up nodepool config with options.
// ApplyTo fills up nodePool config with options.
func (o *PlatformAdminControllerOptions) ApplyTo(cfg *config.PlatformAdminControllerConfiguration) error {
if o == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/yurtappdaemoncontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewYurtAppDaemonControllerOptions() *YurtAppDaemonControllerOptions {
}
}

// AddFlags adds flags related to yurtappdaemon for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to YurtAppDaemon for yurt-manager to the specified FlagSet.
func (o *YurtAppDaemonControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
Expand All @@ -41,7 +41,7 @@ func (o *YurtAppDaemonControllerOptions) AddFlags(fs *pflag.FlagSet) {
//fs.BoolVar(&n.CreateDefaultPool, "create-default-pool", n.CreateDefaultPool, "Create default cloud/edge pools if indicated.")
}

// ApplyTo fills up yurtappdaemon config with options.
// ApplyTo fills up YurtAppDaemon config with options.
func (o *YurtAppDaemonControllerOptions) ApplyTo(cfg *config.YurtAppDaemonControllerConfiguration) error {
if o == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/yurtappoverridercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewYurtAppOverriderControllerOptions() *YurtAppOverriderControllerOptions {
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (n *YurtAppOverriderControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
Expand All @@ -41,7 +41,7 @@ func (n *YurtAppOverriderControllerOptions) AddFlags(fs *pflag.FlagSet) {
//fs.BoolVar(&n.CreateDefaultPool, "create-default-pool", n.CreateDefaultPool, "Create default cloud/edge pools if indicated.")
}

// ApplyTo fills up nodepool config with options.
// ApplyTo fills up nodePool config with options.
func (o *YurtAppOverriderControllerOptions) ApplyTo(cfg *config.YurtAppOverriderControllerConfiguration) error {
if o == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/yurtappsetcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewYurtAppSetControllerOptions() *YurtAppSetControllerOptions {
}
}

// AddFlags adds flags related to nodepool for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to nodePool for yurt-manager to the specified FlagSet.
func (n *YurtAppSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
if n == nil {
return
Expand All @@ -41,7 +41,7 @@ func (n *YurtAppSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
//fs.BoolVar(&n.CreateDefaultPool, "create-default-pool", n.CreateDefaultPool, "Create default cloud/edge pools if indicated.")
}

// ApplyTo fills up nodepool config with options.
// ApplyTo fills up nodePool config with options.
func (o *YurtAppSetControllerOptions) ApplyTo(cfg *config.YurtAppSetControllerConfiguration) error {
if o == nil {
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/yurt-manager/app/options/yurtstaticsetcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewYurtStaticSetControllerOptions() *YurtStaticSetControllerOptions {
}
}

// AddFlags adds flags related to yurtstaticset for yurt-manager to the specified FlagSet.
// AddFlags adds flags related to YurtStaticSet for yurt-manager to the specified FlagSet.
func (o *YurtStaticSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
if o == nil {
return
Expand All @@ -45,7 +45,7 @@ func (o *YurtStaticSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.UpgradeWorkerImage, "node-servant-image", o.UpgradeWorkerImage, "Specify node servant pod image used for YurtStaticSet upgrade.")
}

// ApplyTo fills up yurtstaticset config with options.
// ApplyTo fills up YurtStaticSet config with options.
func (o *YurtStaticSetControllerOptions) ApplyTo(cfg *config.YurtStaticSetControllerConfiguration) error {
if o == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (webhook *NodePoolHandler) ValidateUpdate(ctx context.Context, oldObj, newO
}

if allErrs := validateNodePoolSpecUpdate(&newNp.Spec, &oldNp.Spec); len(allErrs) > 0 {
return apierrors.NewInvalid(appsv1beta1.GroupVersion.WithKind("NodePool").GroupKind(), newNp.Name, allErrs)
return apierrors.NewForbidden(appsv1beta1.GroupVersion.WithResource("nodepools").GroupResource(), newNp.Name, allErrs[0])
}

return nil
Expand All @@ -71,7 +71,7 @@ func (webhook *NodePoolHandler) ValidateDelete(_ context.Context, obj runtime.Ob
return apierrors.NewBadRequest(fmt.Sprintf("expected a NodePool but got a %T", obj))
}
if allErrs := validateNodePoolDeletion(webhook.Client, np); len(allErrs) > 0 {
return apierrors.NewInvalid(appsv1beta1.GroupVersion.WithKind("NodePool").GroupKind(), np.Name, allErrs)
return apierrors.NewForbidden(appsv1beta1.GroupVersion.WithResource("nodepools").GroupResource(), np.Name, allErrs[0])
}

return nil
Expand Down Expand Up @@ -121,12 +121,12 @@ func validateNodePoolSpecUpdate(spec, oldSpec *appsv1beta1.NodePoolSpec) field.E

if spec.Type != oldSpec.Type {
return field.ErrorList([]*field.Error{
field.Invalid(field.NewPath("spec").Child("type"), spec.Type, "pool type can't be changed")})
field.Forbidden(field.NewPath("spec").Child("type"), "pool type can't be changed")})
}

if spec.HostNetwork != oldSpec.HostNetwork {
return field.ErrorList([]*field.Error{
field.Invalid(field.NewPath("spec").Child("hostNetwork"), spec.HostNetwork, "pool hostNetwork can't be changed"),
field.Forbidden(field.NewPath("spec").Child("hostNetwork"), "pool hostNetwork can't be changed"),
})
}
return nil
Expand Down

0 comments on commit 34837d6

Please sign in to comment.