@@ -32,6 +32,7 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req reconcile.Requ
3232 gs := & agonesv1.GameServer {}
3333
3434 if err := r .Get (ctx , req .NamespacedName , gs ); err != nil {
35+
3536 if errors .IsNotFound (err ) {
3637 r .log .Error (err , "Could not find GameServer" )
3738 return reconcile.Result {}, nil
@@ -46,22 +47,21 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req reconcile.Requ
4647 return reconcile.Result {}, nil
4748 }
4849
49- hostname , hostnameFound := getAnnotation ( HostnameAnnotation , gs )
50- _ , externalDnsFound := getAnnotation ( ExternalDnsAnnotation , gs )
50+ exists := externalDnsExists ( gs )
51+ hostname , hostnameFound := getHostnameAnnotation ( gs )
5152
52- if externalDnsFound {
53+ if exists {
5354 r .log .Info (fmt .Sprintf ("External DNS set for %s" , gs .Name ))
5455 return reconcile.Result {}, nil
5556 }
5657
5758 if hostnameFound {
58- _ , err := r .dns .SetExternalDns (hostname , gs )
5959
60- if err != nil {
60+ if res , err := r . dns . SetExternalDns ( hostname , gs ); err != nil {
6161
6262 switch err .(type ) {
6363 case * provider.DNSRecordExists :
64- r .log .Info (err .Error ())
64+ r .log .Info (err .Error (), "HTTPStatusCode" , res . HTTPStatusCode )
6565 default :
6666 r .log .Error (err , "Error creating DNS records" )
6767 return reconcile.Result {}, nil
@@ -70,23 +70,34 @@ func (r *GameServerReconciler) Reconcile(ctx context.Context, req reconcile.Requ
7070 }
7171
7272 r .Get (ctx , req .NamespacedName , gs )
73-
74- if err := setAnnotation (ExternalDnsAnnotation , mcDns .JoinARecordName (hostname , gs .Name ), gs ); err != nil {
75- r .log .Error (err , "Error setting externalDNS annotation" )
76- return reconcile.Result {}, nil
77- }
73+ externalDns := setExternalDnsAnnotation (mcDns .JoinARecordName (hostname , gs .Name ), gs )
7874
7975 if err := r .Update (ctx , gs ); err != nil {
8076 return reconcile.Result {}, err
8177 }
82- r . log . Info ( "GameServer updated" )
83- } else {
84- r . log . Info ( fmt . Sprintf ( "Not hostname annotation for %s" , gs . Name ))
78+
79+ r . log . Info ( fmt . Sprintf ( "GameServer %s externalDNS set to %s" , gs . Name , externalDns ))
80+ return reconcile. Result {}, nil
8581 }
8682
83+ r .log .Info (fmt .Sprintf ("No hostname annotation for %s" , gs .Name ))
8784 return reconcile.Result {}, nil
8885}
8986
87+ func externalDnsExists (gs * agonesv1.GameServer ) bool {
88+ _ , ok := getAnnotation (ExternalDnsAnnotation , gs )
89+ return ok
90+ }
91+
92+ func getHostnameAnnotation (gs * agonesv1.GameServer ) (string , bool ) {
93+ return getAnnotation (HostnameAnnotation , gs )
94+ }
95+
96+ func setExternalDnsAnnotation (recordName string , gs * agonesv1.GameServer ) string {
97+ setAnnotation (ExternalDnsAnnotation , recordName , gs )
98+ return recordName
99+ }
100+
90101func getAnnotation (suffix string , gs * agonesv1.GameServer ) (string , bool ) {
91102 annotation := fmt .Sprintf ("%s/%s" , AnnotationPrefix , suffix )
92103 hostname , ok := gs .Annotations [annotation ]
@@ -98,15 +109,9 @@ func getAnnotation(suffix string, gs *agonesv1.GameServer) (string, bool) {
98109 return hostname , true
99110}
100111
101- func setAnnotation (suffix string , value string , gs * agonesv1.GameServer ) error {
112+ func setAnnotation (suffix string , value string , gs * agonesv1.GameServer ) {
102113 annotation := fmt .Sprintf ("%s/%s" , AnnotationPrefix , ExternalDnsAnnotation )
103-
104- if value == "" || strings .TrimSpace (value ) == "" {
105- return fmt .Errorf ("value for %s annotation empty" , annotation )
106- }
107-
108114 gs .Annotations [annotation ] = value
109- return nil
110115}
111116
112117func isServerAllocated (gs * agonesv1.GameServer ) bool {
0 commit comments