Skip to content

Commit

Permalink
Added Operator Version in debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jan 24, 2024
1 parent 3d81bc4 commit 28f87ea
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/command/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ import (
"fmt"
"os"
"runtime"
"strings"
"time"

k8sruntime "k8s.io/apimachinery/pkg/runtime"

routev1 "github.com/openshift/api/route/v1"
"github.com/operator-framework/operator-lib/leader"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"

Expand Down Expand Up @@ -169,6 +172,37 @@ func OperatorWithSignal(operatorCfg *oconfig.Config, signalHandler context.Conte
return err
}

// code added to get the operator image tag name
config := ctrl.GetConfigOrDie()
if err != nil {
fmt.Printf("Error building kubeconfig: %v\n", err)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Error(err, "Error building kubernetes client: %v\n")
}

// Specify the namespace and deployment name

deploymentName := os.Getenv("OPERATOR_NAME")

deployment, err := clientset.AppsV1().Deployments(operatorNamespace).Get(context.TODO(), deploymentName, metav1.GetOptions{})
if err != nil {
log.Error(err, "Error getting deployment %s in namespace")
}

podTemplate := deployment.Spec.Template

// Iterating through containers in the pod template
for _, container := range podTemplate.Spec.Containers {
// Accessing the container image
image := container.Image
image = strings.Split(image, ":")[1]
log.Info("Operator Image Tag is " + image)
}
// code added to get the operator image tag name ends

log.Info("Registering Components.")

// Setup Scheme for all resources
Expand Down

0 comments on commit 28f87ea

Please sign in to comment.