-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrieve.go
78 lines (58 loc) · 1.98 KB
/
retrieve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package agones
import (
agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
"context"
"github.com/rs/zerolog/log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
)
func (c Client) GetGameServers(ctx context.Context, namespace string, labelSelectors labels.Set) (*agonesv1.GameServerList, error) {
log.Debug().Msg("Fetching game servers")
if labelSelectors == nil {
labelSelectors = labels.Set{}
}
labelSelectors[DeletedGameServerLabel] = "false"
options := metav1.ListOptions{LabelSelector: labelSelectors.String()}
gameservers, err := c.Clientset.
AgonesV1().
GameServers(namespace).
List(ctx, options)
if err != nil {
log.Error().Err(err).Msg("Error fetching game servers")
return nil, err
}
return gameservers, err
}
func (c Client) GetGameServer(ctx context.Context, namespace, name string) (*agonesv1.GameServer, error) {
log.Debug().Msgf("Fetching game server %s", name)
gameserver, err := c.Clientset.
AgonesV1().
GameServers(namespace).
Get(ctx, name, metav1.GetOptions{})
if err != nil {
log.Error().Err(err).Msgf("Failed to get game server %s", name)
return nil, err
}
return gameserver, err
}
func (c Client) GetGameServerByName(ctx context.Context, namespace, name string) (*agonesv1.GameServer, error) {
gameserver, err := c.
AgonesV1().
GameServers(namespace).
Get(ctx, name, metav1.GetOptions{})
if err != nil {
log.Err(err).Msgf("Error getting game servers by name: %v", name)
return nil, err
}
return gameserver, nil
}
func (c Client) IsGameServerReady(ctx context.Context, namespace, name string) (*agonesv1.GameServer, bool) {
gameserver, err := c.GetGameServerByName(ctx, namespace, name)
if err != nil {
log.Err(err).Msgf("Error getting game servers by name: %v", name)
return gameserver, false
}
isReady := gameserver != nil && gameserver.Status.State == agonesv1.GameServerStateReady
isAvailable := c.IsGameServerAvailable(ctx, namespace, name)
return gameserver, isReady && isAvailable
}