agones.dev/agones@v1.54.0/pkg/apis/agones/v1/apihooksfake.go (about) 1 // Copyright 2023 Google LLC All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package v1 16 17 import ( 18 "agones.dev/agones/pkg/apis" 19 corev1 "k8s.io/api/core/v1" 20 "k8s.io/apimachinery/pkg/util/validation/field" 21 ) 22 23 // fakeAPIHooks is a stubabble, fake implementation of APIHooks 24 // This needs to be private, so it doesn't get picked up by the DeepCopy() generation toolkit. 25 type fakeAPIHooks struct { 26 StubValidateGameServerSpec func(*GameServerSpec, *field.Path) field.ErrorList 27 StubValidateScheduling func(apis.SchedulingStrategy, *field.Path) field.ErrorList 28 StubMutateGameServerPod func(*GameServerSpec, *corev1.Pod) error 29 StubSetEviction func(*Eviction, *corev1.Pod) error 30 } 31 32 var _ APIHooks = fakeAPIHooks{} 33 34 // ValidateGameServerSpec is called by GameServer.Validate to allow for product specific validation. 35 func (f fakeAPIHooks) ValidateGameServerSpec(gss *GameServerSpec, fldPath *field.Path) field.ErrorList { 36 if f.StubValidateGameServerSpec != nil { 37 return f.StubValidateGameServerSpec(gss, fldPath) 38 } 39 return nil 40 } 41 42 // ValidateScheduling is called by Fleet and GameServerSet Validate() to allow for product specific validation of scheduling strategy. 43 func (f fakeAPIHooks) ValidateScheduling(strategy apis.SchedulingStrategy, fldPath *field.Path) field.ErrorList { 44 if f.StubValidateScheduling != nil { 45 return f.StubValidateScheduling(strategy, fldPath) 46 } 47 return nil 48 } 49 50 // MutateGameServerPod is called by createGameServerPod to allow for product specific pod mutation. 51 func (f fakeAPIHooks) MutateGameServerPod(gss *GameServerSpec, pod *corev1.Pod) error { 52 if f.StubMutateGameServerPod != nil { 53 return f.StubMutateGameServerPod(gss, pod) 54 } 55 return nil 56 } 57 58 // SetEviction is called by gs.Pod to enforce GameServer.Status.Eviction. 59 func (f fakeAPIHooks) SetEviction(eviction *Eviction, pod *corev1.Pod) error { 60 if f.StubSetEviction != nil { 61 return f.StubSetEviction(eviction, pod) 62 } 63 return nil 64 }