Skip to content

Commit

Permalink
Passthrough autopilot - Adds mutating webhook (#3833)
Browse files Browse the repository at this point in the history
* changes to feature and added a lable to gameserver spec with test
* added test inside gke for passthrough label
* updated install yaml
  • Loading branch information
vicentefb authored May 28, 2024
1 parent 2f1c2a8 commit 4b2910b
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 17 deletions.
48 changes: 48 additions & 0 deletions install/helm/agones/templates/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,54 @@ webhooks:
{{- end }}
{{- if not (default .Values.agones.controller.disableSecret .Values.agones.extensions.disableSecret) }}
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: zzz-agones-mutation-webhook
{{- $annotations := default .Values.agones.controller.mutatingWebhook.annotations .Values.agones.extensions.mutatingWebhook.annotations }}
{{- if $annotations }}
annotations:
{{- toYaml $annotations | nindent 4 }}
{{- end }}
labels:
component: controller
app: {{ template "agones.name" . }}
chart: {{ template "agones.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
webhooks:
- name: mutations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
name: agones-controller-service
namespace: {{ .Release.Namespace }}
path: /mutate
{{- if not .Values.agones.controller.mutatingWebhook.disableCaBundle }}
{{- if .Values.agones.controller.generateTLS }}
caBundle: {{ b64enc $ca.Cert }}
{{- else }}
caBundle: {{ default (.Files.Get "certs/server.crt") .Values.agones.controller.tlsCert | b64enc }}
{{- end }}
{{- end }}
objectSelector:
matchLabels:
agones.dev/port: "autopilot-passthrough"
rules:
- apiGroups:
- ""
resources:
- "pods"
apiVersions:
- "v1"
operations:
- CREATE
{{- end }}
{{- if not .Values.agones.controller.disableSecret }}
---
apiVersion: v1
kind: Secret
metadata:
Expand Down
36 changes: 36 additions & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17599,6 +17599,42 @@ webhooks:
- CREATE
- UPDATE
---
# Source: agones/templates/extensions.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: zzz-agones-mutation-webhook
labels:
component: controller
app: agones
chart: agones-1.41.0-dev
release: agones-manual
heritage: Helm
webhooks:
- name: mutations.agones.dev
admissionReviewVersions:
- v1
sideEffects: None
failurePolicy: Fail
clientConfig:
service:
name: agones-controller-service
namespace: agones-system
path: /mutate
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVjVENDQTFtZ0F3SUJBZ0lVRm5DOUsxT1kzRnFNaWhqN3RWbXh5R3hwUVdzd0RRWUpLb1pJaHZjTkFRRUwKQlFBd2dhb3hDekFKQmdOVkJBWVRBbFZUTVJNd0VRWURWUVFJREFwVGIyMWxMVk4wWVhSbE1ROHdEUVlEVlFRSwpEQVpCWjI5dVpYTXhEekFOQmdOVkJBc01Ca0ZuYjI1bGN6RTBNRElHQTFVRUF3d3JZV2R2Ym1WekxXTnZiblJ5CmIyeHNaWEl0YzJWeWRtbGpaUzVoWjI5dVpYTXRjM2x6ZEdWdExuTjJZekV1TUN3R0NTcUdTSWIzRFFFSkFSWWYKWVdkdmJtVnpMV1JwYzJOMWMzTkFaMjl2WjJ4bFozSnZkWEJ6TG1OdmJUQWVGdzB5TVRBMk16QXhPVFUyTWpGYQpGdzB6TVRBMk1qZ3hPVFUyTWpGYU1JR3FNUXN3Q1FZRFZRUUdFd0pWVXpFVE1CRUdBMVVFQ0F3S1UyOXRaUzFUCmRHRjBaVEVQTUEwR0ExVUVDZ3dHUVdkdmJtVnpNUTh3RFFZRFZRUUxEQVpCWjI5dVpYTXhOREF5QmdOVkJBTU0KSzJGbmIyNWxjeTFqYjI1MGNtOXNiR1Z5TFhObGNuWnBZMlV1WVdkdmJtVnpMWE41YzNSbGJTNXpkbU14TGpBcwpCZ2txaGtpRzl3MEJDUUVXSDJGbmIyNWxjeTFrYVhOamRYTnpRR2R2YjJkc1pXZHliM1Z3Y3k1amIyMH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Qk94CnA5L3J4R0FjSVVjQW04Y3hXa01kaEduNnZOYkNFcXJoVTRJdnZSYlMwVnlrckhPY3RGM25raC9GbnRHQU80RDEKUEgrUThSQXBNK2xBeGtXcFIvNXlHTXdLM05WcS9kc2JaclQ5RHhId0hUU2tqL3JXZVRrWmxIN042MHpZL3JqbwpNUjBJNEtOWHl3WElTcGdNbE93dkxPdGY2aUNYeHJDNyt1RjdyQmxCei9tSUNxYnR0dz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
objectSelector:
matchLabels:
agones.dev/port: "autopilot-passthrough"
rules:
- apiGroups:
- ""
resources:
- "pods"
apiVersions:
- "v1"
operations:
- CREATE
---
# Source: agones/templates/priority-class.yaml
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
Expand Down
21 changes: 19 additions & 2 deletions pkg/cloudproduct/gke/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,18 @@ func (*gkeAutopilot) NewPortAllocator(portRanges map[string]portallocator.PortRa

func (*gkeAutopilot) WaitOnFreePorts() bool { return true }

func checkPassthroughPortPolicy(portPolicy agonesv1.PortPolicy) bool {
// if feature is not enabled and port is Passthrough return true because that should be an invalid port
// if feature is not enabled and port is not Passthrough you can return false because there's no error but check for None port
// if feature is enabled and port is passthrough return false because there is no error
// if feature is enabled and port is not passthrough return false because there is no error but check for None port
return (!runtime.FeatureEnabled(runtime.FeatureAutopilotPassthroughPort) && portPolicy == agonesv1.Passthrough) || portPolicy == agonesv1.Static
}

func (g *gkeAutopilot) ValidateGameServerSpec(gss *agonesv1.GameServerSpec, fldPath *field.Path) field.ErrorList {
allErrs := g.ValidateScheduling(gss.Scheduling, fldPath.Child("scheduling"))
for i, p := range gss.Ports {
if p.PortPolicy != agonesv1.Dynamic && (p.PortPolicy != agonesv1.None || !runtime.FeatureEnabled(runtime.FeaturePortPolicyNone)) {
if p.PortPolicy != agonesv1.Dynamic && (p.PortPolicy != agonesv1.None || !runtime.FeatureEnabled(runtime.FeaturePortPolicyNone)) && checkPassthroughPortPolicy(p.PortPolicy) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("ports").Index(i).Child("portPolicy"), string(p.PortPolicy), errPortPolicyMustBeDynamicOrNone))
}
if p.Range != agonesv1.DefaultPortRange && (p.PortPolicy != agonesv1.None || !runtime.FeatureEnabled(runtime.FeaturePortPolicyNone)) {
Expand Down Expand Up @@ -256,14 +264,23 @@ type autopilotPortAllocator struct {
func (*autopilotPortAllocator) Run(_ context.Context) error { return nil }
func (*autopilotPortAllocator) DeAllocate(gs *agonesv1.GameServer) {}

func checkPassthroughPortPolicyForAutopilot(portPolicy agonesv1.PortPolicy) bool {
// Autopilot can have Dynamic or Passthrough
// if feature is not enabled and port is Passthrough -> true
// if feature is not enabled and port is not Passthrough -> true
// if feature is enabled and port is Passthrough -> false
// if feature is enabled and port is not Passthrough -> true
return !(runtime.FeatureEnabled(runtime.FeatureAutopilotPassthroughPort) && portPolicy == agonesv1.Passthrough)
}

func (apa *autopilotPortAllocator) Allocate(gs *agonesv1.GameServer) *agonesv1.GameServer {
if len(gs.Spec.Ports) == 0 {
return gs // Nothing to do.
}

var ports []agonesv1.GameServerPort
for i, p := range gs.Spec.Ports {
if p.PortPolicy != agonesv1.Dynamic {
if p.PortPolicy != agonesv1.Dynamic && checkPassthroughPortPolicyForAutopilot(p.PortPolicy) {
logger.WithField("gs", gs.Name).WithField("portPolicy", p.PortPolicy).Error(
"GameServer has invalid PortPolicy for Autopilot - this should have been rejected by webhooks. Refusing to assign ports.")
return gs
Expand Down
Loading

0 comments on commit 4b2910b

Please sign in to comment.