Skip to content

Commit

Permalink
Remove FleetAllocation.
Browse files Browse the repository at this point in the history
This removes Fleet Allocation implementations.

Removal of FleetAllocation docs will come in a separate PR, as this
one was large enough already.
  • Loading branch information
markmandel committed Jun 26, 2019
1 parent 2948977 commit 42e60dc
Show file tree
Hide file tree
Showing 44 changed files with 2,210 additions and 2,512 deletions.
10 changes: 2 additions & 8 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/client/informers/externalversions"
"agones.dev/agones/pkg/fleetallocation"
"agones.dev/agones/pkg/fleetautoscalers"
"agones.dev/agones/pkg/fleets"
"agones.dev/agones/pkg/gameserverallocations"
Expand All @@ -45,7 +43,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
"gopkg.in/natefinch/lumberjack.v2"
extclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -186,8 +184,6 @@ func main() {

server.Handle("/", health)

allocationMutex := &sync.Mutex{}

gsCounter := gameservers.NewPerNodeCounter(kubeInformerFactory, agonesInformerFactory)

gsController := gameservers.NewController(wh, health,
Expand All @@ -197,15 +193,13 @@ func main() {
gsSetController := gameserversets.NewController(wh, health, gsCounter,
kubeClient, extClient, agonesClient, agonesInformerFactory)
fleetController := fleets.NewController(wh, health, kubeClient, extClient, agonesClient, agonesInformerFactory)
faController := fleetallocation.NewController(wh, allocationMutex,
kubeClient, extClient, agonesClient, agonesInformerFactory)
gasController := gameserverallocations.NewController(api, health, gsCounter, topNGSForAllocation,
kubeClient, kubeInformerFactory, agonesClient, agonesInformerFactory)
fasController := fleetautoscalers.NewController(wh, health,
kubeClient, extClient, agonesClient, agonesInformerFactory)

rs = append(rs,
httpsServer, gsCounter, gsController, gsSetController, fleetController, faController, fasController, gasController, server)
httpsServer, gsCounter, gsController, gsSetController, fleetController, fasController, gasController, server)

stop := signals.NewStopChannel()

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/allocator-service/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Simple Allocator Service

This service provides an example of using the [Agones API](https://godoc.org/agones.dev/agones/pkg/client/clientset/versioned/typed/stable/v1alpha1) to allocate a GameServer from a Fleet, and is used in the [Create an Allocator Service (Go)](../../docs/create_allocator_service.md) tutorial.
This service provides an example of using the [Agones API](https://godoc.org/agones.dev/agones/pkg/client/clientset/versioned/typed/stable/v1alpha1) to allocate a GameServer from a Fleet, and is used in the [Create an Allocator Service (Go)](https://agones.dev/site/docs/tutorials/allocator-service-go/) tutorial.

## Allocator Service
The service exposes an endpoint which allows client calls to FleetAllocationInterface.Create() over a secure connection. It also provides examples of how to create a service account with the least necessary privileges, how to create an Ingress, and how services can use secrets specific to their respective accounts.
The service exposes an endpoint which allows client calls to AllocationInterface.Create() over a secure connection. It also provides examples of how to create a service account with the least necessary privileges, how to create an Ingress, and how services can use secrets specific to their respective accounts.

When the endpoint is called and a GameServer is allocated, it returns the JSON encoded GameServerStatus of the freshly allocated GameServer.

To learn how to deploy this allocator service to GKE, please see the tutorial [Create an Allocator Service (Go)](../../docs/create_allocator_service.md).
To learn how to deploy this allocator service to GKE, please see the tutorial [Create an Allocator Service (Go)](https://agones.dev/site/docs/tutorials/allocator-service-go/).
57 changes: 25 additions & 32 deletions examples/allocator-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"io"
"net/http"

"agones.dev/agones/pkg/apis/stable/v1alpha1"
allocationv1alpha1 "agones.dev/agones/pkg/apis/allocation/v1alpha1"
stablev1alpha1 "agones.dev/agones/pkg/apis/stable/v1alpha1"
"agones.dev/agones/pkg/client/clientset/versioned"
"agones.dev/agones/pkg/util/runtime" // for the logger
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
)

// Constants which define the fleet and namespace we are using
const namespace = "default"
const fleetname = "simple-udp"
const generatename = "simple-udp-"

// Variables for the logger and Agones Clientset
var (
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 v1alpha1.GameServerStatus `json:"status"`
Status allocationv1alpha1.GameServerAllocationState `json:"status"`
}

// Main will set up an http server and three endpoints
Expand Down Expand Up @@ -119,8 +119,7 @@ func handleAddress(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json")
result, _ := json.Marshal(&result{status})
_, err = io.WriteString(w, string(result))
err = json.NewEncoder(w).Encode(&result{status})
if err != nil {
logger.WithError(err).Fatal("Error writing json from /address")
}
Expand All @@ -131,7 +130,7 @@ func checkReadyReplicas() int32 {
// Get a FleetInterface for this namespace
fleetInterface := agonesClient.StableV1alpha1().Fleets(namespace)
// Get our fleet
fleet, err := fleetInterface.Get(fleetname, v1.GetOptions{})
fleet, err := fleetInterface.Get(fleetname, metav1.GetOptions{})
if err != nil {
logger.WithError(err).Info("Get fleet failed")
}
Expand All @@ -140,45 +139,39 @@ func checkReadyReplicas() int32 {
}

// Move a replica from ready to allocated and return the GameServerStatus
func allocate() (v1alpha1.GameServerStatus, error) {
var result v1alpha1.GameServerStatus

// Log the values used in the fleet allocation
logger.WithField("namespace", namespace).Info("namespace for fa")
logger.WithField("generatename", generatename).Info("generatename for fa")
logger.WithField("fleetname", fleetname).Info("fleetname for fa")
func allocate() (allocationv1alpha1.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")

// Find out how many ready replicas the fleet has - we need at least one
readyReplicas := checkReadyReplicas()
logger.WithField("readyReplicas", readyReplicas).Info("numer of ready replicas")
logger.WithField("readyReplicas", readyReplicas).Info("number of ready replicas")

// 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 result, errors.New("Insufficient ready replicas, cannot create fleet allocation")
return allocationv1alpha1.GameServerAllocationUnAllocated, errors.New("insufficient ready replicas, cannot create fleet allocation")
}

// Get a FleetAllocationInterface for this namespace
fleetAllocationInterface := agonesClient.StableV1alpha1().FleetAllocations(namespace)
// Get a AllocationInterface for this namespace
allocationInterface := agonesClient.AllocationV1alpha1().GameServerAllocations(namespace)

// Define the fleet allocation using the constants set earlier
fa := &v1alpha1.FleetAllocation{
ObjectMeta: v1.ObjectMeta{
GenerateName: generatename, Namespace: namespace,
},
Spec: v1alpha1.FleetAllocationSpec{FleetName: fleetname},
}
// Define the allocation using the constants set earlier
gsa := &allocationv1alpha1.GameServerAllocation{
Spec: allocationv1alpha1.GameServerAllocationSpec{
Required: metav1.LabelSelector{MatchLabels: map[string]string{stablev1alpha1.FleetNameLabel: fleetname}},
}}

// Create a new fleet allocation
newFleetAllocation, err := fleetAllocationInterface.Create(fa)
// Create a new allocation
gsa, err := allocationInterface.Create(gsa)
if err != nil {
// Log and return the error if the call to Create fails
logger.WithError(err).Info("Failed to create fleet allocation")
return result, errors.New("Failed to ceate fleet allocation")
logger.WithError(err).Info("Failed to create allocation")
return allocationv1alpha1.GameServerAllocationUnAllocated, errors.New("failed to create allocation")
}

// Log the GameServer.Staus of the new allocation, then return those values
logger.Info("New GameServer allocated: ", newFleetAllocation.Status.GameServer.Status)
result = newFleetAllocation.Status.GameServer.Status
return result, nil
logger.Info("New GameServer allocated: ", gsa.Status.State)
return gsa.Status.State, nil
}
6 changes: 3 additions & 3 deletions examples/allocator-service/service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["create"]
- apiGroups: ["stable.agones.dev"]
resources: ["fleetallocations"]
- apiGroups: ["allocation.agones.dev"]
resources: ["gameserverallocations"]
verbs: ["create"]
- apiGroups: ["stable.agones.dev"]
resources: [fleets, fleet"]
resources: ["fleets"]
verbs: ["get"]

---
Expand Down
2 changes: 1 addition & 1 deletion examples/fleet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#
# Full example of a Fleet resource - a set of warm GameServers
# that are available to be allocated from.
# To allocate a GameServer from a Fleet, use a FleetAllocation
# To allocate a GameServer from a Fleet, use a GameServerAllocation
#

apiVersion: "stable.agones.dev/v1alpha1"
Expand Down
40 changes: 0 additions & 40 deletions examples/fleetallocation.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions examples/simple-udp/fleetallocation.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions examples/xonotic/fleetallocation.yaml

This file was deleted.

1 change: 0 additions & 1 deletion install/helm/agones/scripts/delete_agones_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ for ns in $namespaces; do
kubectl -n $ns delete fleets --all
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
Expand Down
66 changes: 0 additions & 66 deletions install/helm/agones/templates/crds/fleetallocation.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions install/helm/agones/templates/extensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ webhooks:
- "fleets"
- "gameservers"
- "gameserversets"
- "fleetallocations"
apiVersions:
- "v1alpha1"
operations:
Expand All @@ -84,7 +83,6 @@ webhooks:
resources:
- "fleets"
- "gameserversets"
- "fleetallocations"
apiVersions:
- "v1alpha1"
operations:
Expand Down Expand Up @@ -129,7 +127,6 @@ webhooks:
resources:
- "gameservers"
- "fleets"
- "fleetallocations"
apiVersions:
- "v1alpha1"
operations:
Expand Down
Loading

0 comments on commit 42e60dc

Please sign in to comment.