You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: main.go
    path of file: ./repos/agones/examples/custom-controller
    
    the code of the file until where you have to start completion: // Copyright 2024 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This custom controller is deployed in the Kubernetes cluster, specifically in the agones-system namespace,
// and it's designed to observe and react to changes in GameServer instances.

package main

import (
	"context"
	"fmt"
	"os"

	agonesv1 "agones.dev/agones/pkg/apis/agones/v1"
	"github.com/go-logr/logr"
	"k8s.io/apimachinery/pkg/api/errors"
	ctrl "sigs.k8s.io/controller-runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
	"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

// GameServerReconciler reconciles a GameServer object
type GameServerReconciler
    
func (r *GameServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
	r.Log.Info("Entering Reconcile method.")
	gameServer := &agonesv1.GameServer{}
	err := r.Get(ctx, req.NamespacedName, gameServer)
	if err != nil {
		if errors.IsNotFound(err) {
			r.Log.Info("GameServer resource not found and it must be deleted", "name", req.NamespacedName)
			return ctrl.Result{}, nil
		}
		r.Log.Error(err, "unable to fetch GameServer", "name", req.NamespacedName)
		return ctrl.Result{}, err
	}

	// Log current state and labels
	r.Log.Info("Fetched GameServer", "gameServerName", gameServer.Name, "gameServerNamespace", gameServer.Namespace, "state", gameServer.Status.State, "currentLabels", gameServer.Labels)

	if gameServer.Labels == nil {
		gameServer.Labels = map[string]string{}
	}

	originalState := gameServer.Labels["state"]
	newState := fmt.Sprintf("%v", gameServer.Status.State)
	if originalState == newState {
		return ctrl.Result{}, nil
	}
	gameServer.Labels["state"] = newState

	r.Log.Info("Updating GameServer labels", "originalState", originalState, "newState", newState)

	if err := r.Update(ctx, gameServer); err != nil {
		r.Log.Error(err, "Failed to update GameServer", "name", gameServer.Name)
		return ctrl.Result{}, err
	}
	r.Log.Info("GameServer label updated successfully", "name", gameServer.Name, "updatedLabels", gameServer.Labels)
	return ctrl.Result{}, nil
}