Skip to content

Commit 27b37f5

Browse files
pooneh-mmarkmandel
authored andcommitted
Add GameServerAllocationPolicy CRD and schema definition.
Using Secret from kubernetes/core for cluster connection Adding the client generated code for allocation policy. Setting the group name to multicluster.agones.dev
1 parent 409b84f commit 27b37f5

28 files changed

Lines changed: 1248 additions & 11 deletions

‎build/build-image/gen-crd-client.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ rsync -r /go/src/agones.dev/agones/vendor/k8s.io/ /go/src/k8s.io/
2323
cd /go/src/k8s.io/code-generator
2424
./generate-groups.sh "all" \
2525
agones.dev/agones/pkg/client \
26-
agones.dev/agones/pkg/apis "allocation:v1alpha1 stable:v1alpha1" \
26+
agones.dev/agones/pkg/apis "allocation:v1alpha1 stable:v1alpha1 multicluster:v1alpha1" \
2727
--go-header-file=/go/src/agones.dev/agones/build/boilerplate.go.txt
28+

‎install/helm/agones/scripts/delete_agones_resources.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ for ns in $namespaces; do
3232
kubectl -n $ns delete gameserversets --all
3333
kubectl -n $ns delete gameservers --all
3434
kubectl -n $ns delete fleetallocations --all
35+
kubectl -n $ns delete gameserverallocationpolicies --all
3536

3637
# Since we don't have the nifty kubectl wait yet, hack one in the meantime
3738
for p in $pods; do
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2019 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+
{{- if .Values.agones.crds.install }}
16+
17+
apiVersion: apiextensions.k8s.io/v1beta1
18+
kind: CustomResourceDefinition
19+
metadata:
20+
creationTimestamp: null
21+
labels:
22+
controller-tools.k8s.io: "1.0"
23+
component: crd
24+
app: {{ template "agones.name" . }}
25+
chart: {{ template "agones.chart" . }}
26+
release: {{ .Release.Name }}
27+
heritage: {{ .Release.Service }}
28+
name: gameserverallocationpolicies.multicluster.agones.dev
29+
spec:
30+
group: multicluster.agones.dev
31+
names:
32+
kind: GameServerAllocationPolicy
33+
plural: gameserverallocationpolicies
34+
scope: Namespaced
35+
validation:
36+
openAPIV3Schema:
37+
properties:
38+
apiVersion:
39+
description: 'APIVersion defines the versioned schema of this representation
40+
of an object. Servers should convert recognized schemas to the latest
41+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
42+
type: string
43+
kind:
44+
description: 'Kind is a string value representing the REST resource this
45+
object represents. Servers may infer this from the endpoint the client
46+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
47+
type: string
48+
metadata:
49+
type: object
50+
spec:
51+
properties:
52+
connectionInfo:
53+
properties:
54+
secretName:
55+
type: string
56+
apiServerEndpoint:
57+
type: string
58+
clusterName:
59+
type: string
60+
required:
61+
- clusterName
62+
- apiServerEndpoint
63+
- secretName
64+
type: object
65+
priority:
66+
format: int64
67+
minimum: 0
68+
type: integer
69+
weight:
70+
format: int64
71+
minimum: 0
72+
type: integer
73+
required:
74+
- priority
75+
- weight
76+
type: object
77+
version: v1alpha1
78+
status:
79+
acceptedNames:
80+
kind: ""
81+
plural: ""
82+
conditions: []
83+
storedVersions: []
84+
{{- end }}

‎install/helm/agones/templates/hooks/sa.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ metadata:
4545
"helm.sh/hook-delete-policy": before-hook-creation
4646
rules:
4747
- apiGroups: ["stable.agones.dev"]
48-
resources: ["fleets", "fleetallocations", "fleetautoscalers", "gameservers", "gameserversets"]
48+
resources: ["fleets", "fleetallocations", "fleetautoscalers", "gameservers", "gameserversets", "gameserverallocationpolicies"]
4949
verbs: ["delete", "list" ]
5050
- apiGroups: [""]
5151
resources: ["pods"]

‎install/yaml/install.yaml‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,90 @@ spec:
677677
minimum: 1
678678
maximum: 2147483648
679679

680+
---
681+
# Source: agones/templates/crds/gameserverallocationpolicy.yaml
682+
# Copyright 2019 Google LLC All Rights Reserved.
683+
#
684+
# Licensed under the Apache License, Version 2.0 (the "License");
685+
# you may not use this file except in compliance with the License.
686+
# You may obtain a copy of the License at
687+
#
688+
# http://www.apache.org/licenses/LICENSE-2.0
689+
#
690+
# Unless required by applicable law or agreed to in writing, software
691+
# distributed under the License is distributed on an "AS IS" BASIS,
692+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
693+
# See the License for the specific language governing permissions and
694+
# limitations under the License.
695+
696+
apiVersion: apiextensions.k8s.io/v1beta1
697+
kind: CustomResourceDefinition
698+
metadata:
699+
creationTimestamp: null
700+
labels:
701+
controller-tools.k8s.io: "1.0"
702+
component: crd
703+
app: agones
704+
chart: agones-0.10.0
705+
release: agones-manual
706+
heritage: Tiller
707+
name: gameserverallocationpolicies.multicluster.agones.dev
708+
spec:
709+
group: multicluster.agones.dev
710+
names:
711+
kind: GameServerAllocationPolicy
712+
plural: gameserverallocationpolicies
713+
scope: Namespaced
714+
validation:
715+
openAPIV3Schema:
716+
properties:
717+
apiVersion:
718+
description: 'APIVersion defines the versioned schema of this representation
719+
of an object. Servers should convert recognized schemas to the latest
720+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
721+
type: string
722+
kind:
723+
description: 'Kind is a string value representing the REST resource this
724+
object represents. Servers may infer this from the endpoint the client
725+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
726+
type: string
727+
metadata:
728+
type: object
729+
spec:
730+
properties:
731+
connectionInfo:
732+
properties:
733+
secretName:
734+
type: string
735+
apiServerEndpoint:
736+
type: string
737+
clusterName:
738+
type: string
739+
required:
740+
- clusterName
741+
- apiServerEndpoint
742+
- secretName
743+
type: object
744+
priority:
745+
format: int64
746+
minimum: 0
747+
type: integer
748+
weight:
749+
format: int64
750+
minimum: 0
751+
type: integer
752+
required:
753+
- priority
754+
- weight
755+
type: object
756+
version: v1alpha1
757+
status:
758+
acceptedNames:
759+
kind: ""
760+
plural: ""
761+
conditions: []
762+
storedVersions: []
763+
680764
---
681765
# Source: agones/templates/crds/gameserverset.yaml
682766
# Copyright 2018 Google LLC All Rights Reserved.

‎pkg/apis/multicluster/register.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2019 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 multicluster
16+
17+
const (
18+
// GroupName is the Scheme Group Name for Agones Custom Resource Definitions
19+
GroupName = "multicluster.agones.dev"
20+
// VersionAnnotation is the key for version annotation
21+
// associated with the CRD
22+
VersionAnnotation = GroupName + "/sdk-version"
23+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2019 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 v1alpha1
16+
17+
import (
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
)
20+
21+
// GameServerAllocationPolicySpec defines the desired state of GameServerAllocationPolicy
22+
type GameServerAllocationPolicySpec struct {
23+
// +kubebuilder:validation:Minimum=0
24+
Priority int `json:"priority"`
25+
// +kubebuilder:validation:Minimum=0
26+
Weight int `json:"weight"`
27+
ConnectionInfo ClusterConnectionInfo `json:"connectionInfo,omitempty"`
28+
}
29+
30+
// ClusterConnectionInfo defines the connection information for a cluster
31+
type ClusterConnectionInfo struct {
32+
ClusterName string `json:"clusterName"`
33+
APIServerEndpoint string `json:"apiServerEndpoint"`
34+
SecretName string `json:"secretName"`
35+
}
36+
37+
// +genclient
38+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
39+
40+
// GameServerAllocationPolicy is the Schema for the gameserverallocationpolicies API
41+
// +k8s:openapi-gen=true
42+
type GameServerAllocationPolicy struct {
43+
metav1.TypeMeta `json:",inline"`
44+
metav1.ObjectMeta `json:"metadata,omitempty"`
45+
46+
Spec GameServerAllocationPolicySpec `json:"spec,omitempty"`
47+
}
48+
49+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
50+
51+
// GameServerAllocationPolicyList contains a list of GameServerAllocationPolicy
52+
type GameServerAllocationPolicyList struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ListMeta `json:"metadata,omitempty"`
55+
Items []GameServerAllocationPolicy `json:"items"`
56+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2019 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 v1alpha1
16+
17+
import (
18+
"agones.dev/agones/pkg/apis/multicluster"
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
k8sruntime "k8s.io/apimachinery/pkg/runtime"
21+
"k8s.io/apimachinery/pkg/runtime/schema"
22+
"k8s.io/client-go/kubernetes/scheme"
23+
)
24+
25+
// SchemeGroupVersion is group version used to register these objects
26+
var SchemeGroupVersion = schema.GroupVersion{Group: multicluster.GroupName, Version: "v1alpha1"}
27+
28+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
29+
func Kind(kind string) schema.GroupKind {
30+
return SchemeGroupVersion.WithKind(kind).GroupKind()
31+
}
32+
33+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
34+
func Resource(resource string) schema.GroupResource {
35+
return SchemeGroupVersion.WithResource(resource).GroupResource()
36+
}
37+
38+
var (
39+
// SchemeBuilder registers our types
40+
SchemeBuilder = k8sruntime.NewSchemeBuilder(addKnownTypes)
41+
// AddToScheme local alias for SchemeBuilder.AddToScheme
42+
AddToScheme = SchemeBuilder.AddToScheme
43+
)
44+
45+
func init() {
46+
if err := AddToScheme(scheme.Scheme); err != nil {
47+
panic(err)
48+
}
49+
}
50+
51+
// Adds the list of known types to api.Scheme.
52+
func addKnownTypes(scheme *k8sruntime.Scheme) error {
53+
scheme.AddKnownTypes(SchemeGroupVersion,
54+
&GameServerAllocationPolicy{},
55+
&GameServerAllocationPolicyList{},
56+
)
57+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
58+
return nil
59+
}

0 commit comments

Comments
 (0)