Skip to content

Commit

Permalink
Add the ability to pass labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Suderman committed Jun 23, 2020
1 parent 88b73cb commit d76b69a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
demoCount int
demoDelay int
demoDuration int
labelSelector map[string]string
)

func init() {
Expand All @@ -49,6 +50,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&host, "host", "", "", "The hostname or IP address of the allocator server")
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "", "The namespace of gameservers to request from")
rootCmd.PersistentFlags().BoolVarP(&multicluster, "multicluster", "m", false, "If true, multicluster allocation will be requested")
rootCmd.PersistentFlags().StringToStringVar(&labelSelector, "labels", nil, "A map of labels to match on the allocation.")

rootCmd.AddCommand(allocateCmd)
rootCmd.AddCommand(loadTestCmd)
Expand Down Expand Up @@ -106,7 +108,7 @@ var allocateCmd = &cobra.Command{
Long: `Request an allocated server`,
PreRunE: argsValidator,
Run: func(cmd *cobra.Command, args []string) {
allocatorClient, err := allocator.NewClient(keyFile, certFile, caCertFile, host, namespace, multicluster)
allocatorClient, err := allocator.NewClient(keyFile, certFile, caCertFile, host, namespace, multicluster, labelSelector)
if err != nil {
klog.Error(err)
}
Expand All @@ -125,7 +127,7 @@ var loadTestCmd = &cobra.Command{
Long: `Allocates a set of servers, communicates with them, and then closes the connection.`,
PreRunE: argsValidator,
Run: func(cmd *cobra.Command, args []string) {
allocatorClient, err := allocator.NewClient(keyFile, certFile, caCertFile, host, namespace, multicluster)
allocatorClient, err := allocator.NewClient(keyFile, certFile, caCertFile, host, namespace, multicluster, labelSelector)
if err != nil {
klog.Error(err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Client struct {
Namespace string
Multicluster bool
DialOpts grpc.DialOption
MatchLabels map[string]string
}

// Allocation is a game server allocation
Expand All @@ -47,7 +48,7 @@ type Allocation struct {
}

// NewClient builds a new client object
func NewClient(keyFile string, certFile string, cacertFile string, externalIP string, namespace string, multiCluster bool) (*Client, error) {
func NewClient(keyFile, certFile, cacertFile, externalIP, namespace string, multiCluster bool, labelSelector map[string]string) (*Client, error) {
endpoint := externalIP + ":443"
cert, err := ioutil.ReadFile(certFile)
if err != nil {
Expand All @@ -69,6 +70,7 @@ func NewClient(keyFile string, certFile string, cacertFile string, externalIP st
Endpoint: endpoint,
Multicluster: multiCluster,
Namespace: namespace,
MatchLabels: labelSelector,
}
err = newClient.createRemoteClusterDialOption()
if err != nil {
Expand Down Expand Up @@ -107,6 +109,9 @@ func (c *Client) AllocateGameserver() (*Allocation, error) {
MultiClusterSetting: &pb.MultiClusterSetting{
Enabled: c.Multicluster,
},
RequiredGameServerSelector: &pb.LabelSelector{
MatchLabels: c.MatchLabels,
},
}

resp, err := c.makeRequest(request)
Expand Down

0 comments on commit d76b69a

Please sign in to comment.