Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allocation policy CRD and schema definition. #698

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/build-image/gen-crd-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ rsync -r /go/src/agones.dev/agones/vendor/k8s.io/ /go/src/k8s.io/
cd /go/src/k8s.io/code-generator
./generate-groups.sh "all" \
agones.dev/agones/pkg/client \
agones.dev/agones/pkg/apis "allocation:v1alpha1 stable:v1alpha1" \
agones.dev/agones/pkg/apis "allocation:v1alpha1 stable:v1alpha1 multicluster:v1alpha1" \
--go-header-file=/go/src/agones.dev/agones/build/boilerplate.go.txt

1 change: 1 addition & 0 deletions install/helm/agones/scripts/delete_agones_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ for ns in $namespaces; do
kubectl -n $ns delete gameserversets --all
kubectl -n $ns delete gameservers --all
kubectl -n $ns delete fleetallocations --all
kubectl -n $ns delete gameserverallocationpolicies --all

# Since we don't have the nifty kubectl wait yet, hack one in the meantime
for p in $pods; do
Expand Down
84 changes: 84 additions & 0 deletions install/helm/agones/templates/crds/gameserverallocationpolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{{- if .Values.agones.crds.install }}

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
component: crd
app: {{ template "agones.name" . }}
chart: {{ template "agones.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: gameserverallocationpolicies.multicluster.agones.dev
spec:
group: multicluster.agones.dev
names:
kind: GameServerAllocationPolicy
plural: gameserverallocationpolicies
scope: Namespaced
validation:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
connectionInfo:
properties:
secretName:
type: string
apiServerEndpoint:
type: string
clusterName:
type: string
required:
- clusterName
- apiServerEndpoint
- secretName
type: object
priority:
format: int64
minimum: 0
type: integer
weight:
format: int64
minimum: 0
type: integer
required:
- priority
- weight
type: object
version: v1alpha1
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
{{- end }}
2 changes: 1 addition & 1 deletion install/helm/agones/templates/hooks/sa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ metadata:
"helm.sh/hook-delete-policy": before-hook-creation
rules:
- apiGroups: ["stable.agones.dev"]
resources: ["fleets", "fleetallocations", "fleetautoscalers", "gameservers", "gameserversets"]
resources: ["fleets", "fleetallocations", "fleetautoscalers", "gameservers", "gameserversets", "gameserverallocationpolicies"]
verbs: ["delete", "list" ]
- apiGroups: [""]
resources: ["pods"]
Expand Down
84 changes: 84 additions & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,90 @@ spec:
minimum: 1
maximum: 2147483648

---
# Source: agones/templates/crds/gameserverallocationpolicy.yaml
# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: null
labels:
controller-tools.k8s.io: "1.0"
component: crd
app: agones
chart: agones-0.10.0
release: agones-manual
heritage: Tiller
name: gameserverallocationpolicies.multicluster.agones.dev
spec:
group: multicluster.agones.dev
names:
kind: GameServerAllocationPolicy
plural: gameserverallocationpolicies
scope: Namespaced
validation:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
connectionInfo:
properties:
secretName:
type: string
apiServerEndpoint:
type: string
clusterName:
type: string
required:
- clusterName
- apiServerEndpoint
- secretName
type: object
priority:
format: int64
minimum: 0
type: integer
weight:
format: int64
minimum: 0
type: integer
required:
- priority
- weight
type: object
version: v1alpha1
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

---
# Source: agones/templates/crds/gameserverset.yaml
# Copyright 2018 Google LLC All Rights Reserved.
Expand Down
23 changes: 23 additions & 0 deletions pkg/apis/multicluster/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2019 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package multicluster

const (
// GroupName is the Scheme Group Name for Agones Custom Resource Definitions
GroupName = "multicluster.agones.dev"
// VersionAnnotation is the key for version annotation
// associated with the CRD
VersionAnnotation = GroupName + "/sdk-version"
)
56 changes: 56 additions & 0 deletions pkg/apis/multicluster/v1alpha1/gameserverallocationpolicy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2019 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GameServerAllocationPolicySpec defines the desired state of GameServerAllocationPolicy
type GameServerAllocationPolicySpec struct {
// +kubebuilder:validation:Minimum=0
Priority int `json:"priority"`
// +kubebuilder:validation:Minimum=0
Weight int `json:"weight"`
ConnectionInfo ClusterConnectionInfo `json:"connectionInfo,omitempty"`
}

// ClusterConnectionInfo defines the connection information for a cluster
type ClusterConnectionInfo struct {
ClusterName string `json:"clusterName"`
APIServerEndpoint string `json:"apiServerEndpoint"`
SecretName string `json:"secretName"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// GameServerAllocationPolicy is the Schema for the gameserverallocationpolicies API
// +k8s:openapi-gen=true
type GameServerAllocationPolicy struct {
pooneh-m marked this conversation as resolved.
Show resolved Hide resolved
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GameServerAllocationPolicySpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// GameServerAllocationPolicyList contains a list of GameServerAllocationPolicy
type GameServerAllocationPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GameServerAllocationPolicy `json:"items"`
}
59 changes: 59 additions & 0 deletions pkg/apis/multicluster/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2019 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
"agones.dev/agones/pkg/apis/multicluster"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: multicluster.GroupName, Version: "v1alpha1"}

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// SchemeBuilder registers our types
SchemeBuilder = k8sruntime.NewSchemeBuilder(addKnownTypes)
// AddToScheme local alias for SchemeBuilder.AddToScheme
AddToScheme = SchemeBuilder.AddToScheme
)

func init() {
if err := AddToScheme(scheme.Scheme); err != nil {
panic(err)
}
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *k8sruntime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&GameServerAllocationPolicy{},
&GameServerAllocationPolicyList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
Loading