Skip to content

Commit

Permalink
Promote allocation to v1 (#881)
Browse files Browse the repository at this point in the history
* Rename the allocation API from v1alpha1 -> v1.
* Run `make gen-crd-client`.
* Code updated for the new allocation import path.
* Updates for the new allocation api version.
* Force a rebuild of the build image.
* Update website docs.
* Run `make gen-api-docs`.
* Run `make gen-install`.
  • Loading branch information
roberthbailey authored and markmandel committed Jul 10, 2019
1 parent a8295b9 commit 194293e
Show file tree
Hide file tree
Showing 39 changed files with 318 additions and 253 deletions.
2 changes: 1 addition & 1 deletion build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# ForceUpdate 9 -- change here if you need to force a rebuild
# ForceUpdate 10 -- change here if you need to force a rebuild

FROM debian:stretch

Expand Down
2 changes: 1 addition & 1 deletion build/build-image/gen-crd-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +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 multicluster:v1alpha1 autoscaling:v1" \
agones.dev/agones/pkg/apis "allocation:v1 stable:v1alpha1 multicluster:v1alpha1 autoscaling:v1" \
--go-header-file=/go/src/agones.dev/agones/build/boilerplate.go.txt

8 changes: 4 additions & 4 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"
"strings"

allocationv1alpha1 "agones.dev/agones/pkg/apis/allocation/v1alpha1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/util/runtime"
k8serror "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -55,7 +55,7 @@ func main() {
}

// TODO: add liveness probe
http.HandleFunc("/v1alpha1/gameserverallocation", h.postOnly(h.allocateHandler))
http.HandleFunc("/v1/gameserverallocation", h.postOnly(h.allocateHandler))

caCertPool, err := getCACertPool(certDir)
if err != nil {
Expand Down Expand Up @@ -134,13 +134,13 @@ type httpHandler struct {
}

func (h *httpHandler) allocateHandler(w http.ResponseWriter, r *http.Request) {
gsa := allocationv1alpha1.GameServerAllocation{}
gsa := allocationv1.GameServerAllocation{}
if err := json.NewDecoder(r.Body).Decode(&gsa); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest)
return
}

allocation := h.agonesClient.AllocationV1alpha1().GameServerAllocations(gsa.ObjectMeta.Namespace)
allocation := h.agonesClient.AllocationV1().GameServerAllocations(gsa.ObjectMeta.Namespace)
allocatedGsa, err := allocation.Create(&gsa)
if err != nil {
http.Error(w, err.Error(), httpCode(err))
Expand Down
16 changes: 8 additions & 8 deletions cmd/allocator/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"testing"

"agones.dev/agones/pkg/apis/allocation/v1alpha1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
agonesfake "agones.dev/agones/pkg/client/clientset/versioned/fake"
"github.com/stretchr/testify/assert"
k8serror "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -40,17 +40,17 @@ func TestAllocateHandler(t *testing.T) {
}

fakeAgones.AddReactor("create", "gameserverallocations", func(action k8stesting.Action) (bool, k8sruntime.Object, error) {
return true, &v1alpha1.GameServerAllocation{
return true, &allocationv1.GameServerAllocation{
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
},
Status: v1alpha1.GameServerAllocationStatus{
State: v1alpha1.GameServerAllocationContention,
Status: allocationv1.GameServerAllocationStatus{
State: allocationv1.GameServerAllocationContention,
},
}, nil
})

gsa := &v1alpha1.GameServerAllocation{}
gsa := &allocationv1.GameServerAllocation{}
body, _ := json.Marshal(gsa)
buf := bytes.NewBuffer(body)
req, err := http.NewRequest(http.MethodPost, "/", buf)
Expand All @@ -61,12 +61,12 @@ func TestAllocateHandler(t *testing.T) {
rec := httptest.NewRecorder()
h.allocateHandler(rec, req)

ret := &v1alpha1.GameServerAllocation{}
ret := &allocationv1.GameServerAllocation{}
assert.Equal(t, rec.Code, 200)
assert.Equal(t, "application/json", rec.Header()["Content-Type"][0])
err = json.Unmarshal(rec.Body.Bytes(), ret)
assert.NoError(t, err)
assert.Equal(t, v1alpha1.GameServerAllocationContention, ret.Status.State)
assert.Equal(t, allocationv1.GameServerAllocationContention, ret.Status.State)
}

func TestAllocateHandlerReturnsError(t *testing.T) {
Expand All @@ -81,7 +81,7 @@ func TestAllocateHandlerReturnsError(t *testing.T) {
return true, nil, k8serror.NewBadRequest("error")
})

gsa := &v1alpha1.GameServerAllocation{}
gsa := &allocationv1.GameServerAllocation{}
body, _ := json.Marshal(gsa)
buf := bytes.NewBuffer(body)
req, err := http.NewRequest(http.MethodPost, "/", buf)
Expand Down
16 changes: 8 additions & 8 deletions examples/allocator-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
"net/http"

allocationv1alpha1 "agones.dev/agones/pkg/apis/allocation/v1alpha1"
allocationv1 "agones.dev/agones/pkg/apis/allocation/v1"
stablev1alpha1 "agones.dev/agones/pkg/apis/stable/v1alpha1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/util/runtime" // for the logger
Expand All @@ -29,7 +29,7 @@ type handler func(w http.ResponseWriter, r *http.Request)

// The structure of the json response
type result struct {
Status allocationv1alpha1.GameServerAllocationState `json:"status"`
Status allocationv1.GameServerAllocationState `json:"status"`
}

// Main will set up an http server and three endpoints
Expand Down Expand Up @@ -139,7 +139,7 @@ func checkReadyReplicas() int32 {
}

// Move a replica from ready to allocated and return the GameServerStatus
func allocate() (allocationv1alpha1.GameServerAllocationState, error) {
func allocate() (allocationv1.GameServerAllocationState, error) {
// Log the values used in the allocation
logger.WithField("namespace", namespace).Info("namespace for gsa")
logger.WithField("fleetname", fleetname).Info("fleetname for gsa")
Expand All @@ -151,15 +151,15 @@ func allocate() (allocationv1alpha1.GameServerAllocationState, error) {
// Log and return an error if there are no ready replicas
if readyReplicas < 1 {
logger.WithField("fleetname", fleetname).Info("Insufficient ready replicas, cannot create fleet allocation")
return allocationv1alpha1.GameServerAllocationUnAllocated, errors.New("insufficient ready replicas, cannot create fleet allocation")
return allocationv1.GameServerAllocationUnAllocated, errors.New("insufficient ready replicas, cannot create fleet allocation")
}

// Get a AllocationInterface for this namespace
allocationInterface := agonesClient.AllocationV1alpha1().GameServerAllocations(namespace)
allocationInterface := agonesClient.AllocationV1().GameServerAllocations(namespace)

// Define the allocation using the constants set earlier
gsa := &allocationv1alpha1.GameServerAllocation{
Spec: allocationv1alpha1.GameServerAllocationSpec{
gsa := &allocationv1.GameServerAllocation{
Spec: allocationv1.GameServerAllocationSpec{
Required: metav1.LabelSelector{MatchLabels: map[string]string{stablev1alpha1.FleetNameLabel: fleetname}},
}}

Expand All @@ -168,7 +168,7 @@ func allocate() (allocationv1alpha1.GameServerAllocationState, error) {
if err != nil {
// Log and return the error if the call to Create fails
logger.WithError(err).Info("Failed to create allocation")
return allocationv1alpha1.GameServerAllocationUnAllocated, errors.New("failed to create allocation")
return allocationv1.GameServerAllocationUnAllocated, errors.New("failed to create allocation")
}

// Log the GameServer.Staus of the new allocation, then return those values
Expand Down
2 changes: 1 addition & 1 deletion examples/gameserverallocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# multiple Fleets, or a self managed group of GameServers.
#

apiVersion: "allocation.agones.dev/v1alpha1"
apiVersion: "allocation.agones.dev/v1"
kind: GameServerAllocation
spec:
# GameServer selector from which to choose GameServers from.
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-udp/gameserverallocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# A GameServerAllocation against a Fleet named 'simple-udp'
#

apiVersion: "allocation.agones.dev/v1alpha1"
apiVersion: "allocation.agones.dev/v1"
kind: GameServerAllocation
spec:
# GameServer selector from which to choose GameServers from.
Expand Down
2 changes: 1 addition & 1 deletion examples/xonotic/gameserverallocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: "allocation.agones.dev/v1alpha1"
apiVersion: "allocation.agones.dev/v1"
kind: GameServerAllocation
spec:
# GameServer selector from which to choose GameServers from.
Expand Down
4 changes: 2 additions & 2 deletions install/helm/agones/templates/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1alpha1.allocation.agones.dev
name: v1.allocation.agones.dev
labels:
component: controller
app: {{ template "agones.name" . }}
Expand All @@ -40,7 +40,7 @@ spec:
{{- else }}
caBundle: {{ .Files.Get "certs/server.crt" | b64enc }}
{{- end }}
version: v1alpha1
version: v1
{{- end}}
{{- if .Values.agones.registerWebhooks }}
---
Expand Down
4 changes: 2 additions & 2 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ spec:
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1alpha1.allocation.agones.dev
name: v1.allocation.agones.dev
labels:
component: controller
app: agones
Expand All @@ -1399,7 +1399,7 @@ spec:
name: agones-controller-service
namespace: agones-system
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVLVENDQXhHZ0F3SUJBZ0lKQU9KUDY0MTB3dkdTTUEwR0NTcUdTSWIzRFFFQkN3VUFNSUdxTVFzd0NRWUQKVlFRR0V3SlZVekVUTUJFR0ExVUVDQXdLVTI5dFpTMVRkR0YwWlRFUE1BMEdBMVVFQ2d3R1FXZHZibVZ6TVE4dwpEUVlEVlFRTERBWkJaMjl1WlhNeE5EQXlCZ05WQkFNTUsyRm5iMjVsY3kxamIyNTBjbTlzYkdWeUxYTmxjblpwClkyVXVZV2R2Ym1WekxYTj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0eEhtZEcwd0h3WURWUjBqQkJnd0ZvQVVndjFuVFBhUUpTTjMKTHFtNWpJalc0eEhtZEcwd0RBWURWUjBUQkFVd0F3RUIvekFOQmdrcWhraUc5dzBCQVFzRkFBT0NBUUVBSEtFQwprdEVqWU5VQ0ErbXlzejRvclc3cFJVdmhCSERWU2dzWTZlRVZSTHpmLzF5SVpFMHU2NTZrcEs2T1Q3TWhKR2xVCkt3R1NTb1VCQnpWZ1VzWmpEbTdQZ2JrNGlZem40TTF4THpiTFFCcjNNYzV6WEhlZlB2YmltaEQ1NWNMenBWRnUKVlFtQm1aVjJOalU1RHVTZFJuZGxjUGFOY2cvdU9jdlpLNEtZMUtDQkEzRW9BUUlrcHpIWDJpVU1veGlSdlpWTgpORXdnRlR0SUdCWW4wSGZML3ZnT3NIOGZWck1Va3VHMnZoR2RlWEJwWmlxL0JaSmJaZU4yckNmMmdhWDFRSXYwCkVLYmN1RnFNOThXVDVaVlpSdFgxWTNSd2V2ZzRteFlKWEN1SDZGRjlXOS9TejI5NEZ5Mk9CS0I4SkFWYUV4OW4KMS9pNmZJZmZHbkhUWFdIc1ZRPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
version: v1alpha1
version: v1
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

// +k8s:deepcopy-gen=package,register

// Package v1alpha1 is the v1alpha1 version of the API.
// Package v1 is the v1 version of the API.
// +groupName=allocation.agones.dev
package v1alpha1
package v1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1
package v1

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1
package v1

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1
package v1

import (
"agones.dev/agones/pkg/apis/allocation"
Expand All @@ -23,7 +23,7 @@ import (
)

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

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions pkg/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 194293e

Please sign in to comment.