func (v *virtualGatewayValidator) enforceFieldsImmutability(newVGateway *appmesh.VirtualGateway, oldVGateway *appmesh.VirtualGateway) error {
	var changedImmutableFields []string
	if !reflect.DeepEqual(newVGateway.Spec.AWSName, oldVGateway.Spec.AWSName) {
		changedImmutableFields = append(changedImmutableFields, "spec.awsName")
	}
	if !reflect.DeepEqual(newVGateway.Spec.MeshRef, oldVGateway.Spec.MeshRef) {
		changedImmutableFields = append(changedImmutableFields, "spec.meshRef")
	}
	if len(changedImmutableFields) != 0 {
		return errors.Errorf("%s update may not change these fields: %s", "VirtualGateway", strings.Join(changedImmutableFields, ","))
	}
	return nil
}
enforceFieldsImmutability will enforce immutable fields are not changed.
package appmesh
import (
	"context"
	appmesh "github.com/aws/aws-app-mesh-controller-for-k8s/apis/appmesh/v1beta2"
	"github.com/aws/aws-app-mesh-controller-for-k8s/pkg/webhook"
	"github.com/pkg/errors"
	"k8s.io/apimachinery/pkg/runtime"
	"reflect"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
	"strings"
)
const apiPathValidateAppMeshVirtualGateway = "/validate-appmesh-k8s-aws-v1beta2-virtualgateway"
func NewVirtualGatewayValidator() *virtualGatewayValidator {
	return &virtualGatewayValidator{}
}
var _ webhook.Validator = &virtualGatewayValidator{}
type virtualGatewayValidator struct {
}
func (v *virtualGatewayValidator) Prototype(req admission.Request) (runtime.Object, error) {
	return &appmesh.VirtualGateway{}, nil
}
func (v *virtualGatewayValidator) ValidateCreate(ctx context.Context, obj runtime.Object) error {
	vg := obj.(*appmesh.VirtualGateway)
	if err := v.checkForConnectionPoolProtocols(vg); err != nil {
		return err
	}
	return nil
}
func (v *virtualGatewayValidator) ValidateUpdate(ctx context.Context, obj runtime.Object, oldObj runtime.Object) error {
	vg := obj.(*appmesh.VirtualGateway)
	oldVGateway := oldObj.(*appmesh.VirtualGateway)
	if err := v.enforceFieldsImmutability(vg, oldVGateway); err != nil {
		return err
	}
	if err := v.checkForConnectionPoolProtocols(vg); err != nil {
		return err
	}
	return nil
}
func (v *virtualGatewayValidator) ValidateDelete(ctx context.Context, obj runtime.Object) error {
	return nil
}