Skip to content

Commit

Permalink
use klog
Browse files Browse the repository at this point in the history
use klog
  • Loading branch information
jiuker authored and pjuarezd committed Jul 17, 2024
1 parent 7a73b3d commit 7196b59
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sidecar/pkg/sidecar/sidecar_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {

// StartSideCar instantiates kube clients and starts the side-car controller
func StartSideCar(tenantName string, secretName string) {
log.Println("Starting Sidecar")
klog.Infoln("Starting Sidecar")
cfg, err := rest.InClusterConfig()
if err != nil {
panic(err)
Expand All @@ -70,7 +70,7 @@ func StartSideCar(tenantName string, secretName string) {
// get the only tenant in this namespace
tenant, err := controllerClient.MinioV2().Tenants(namespace).Get(context.Background(), tenantName, metav1.GetOptions{})
if err != nil {
log.Fatal(err)
klog.Fatal(err)
}

tenant.EnsureDefaults()
Expand Down Expand Up @@ -165,7 +165,7 @@ func NewSideCarController(kubeClient *kubernetes.Clientset, controllerClient *cl
if oldSecret.Name != secretName {
return
}
log.Printf("Config secret '%s' sync", secretName)
klog.Infof("Config secret '%s' sync", secretName)
newSecret := new.(*corev1.Secret)
if newSecret.ResourceVersion == oldSecret.ResourceVersion {
// Periodic resync will send update events for all known Tenants.
Expand All @@ -191,8 +191,8 @@ func NewSideCarController(kubeClient *kubernetes.Clientset, controllerClient *cl
rootPwdFound = true
}
if !rootUserFound || !rootPwdFound {
log.Println("Missing root credentials in the configuration.")
log.Println("MinIO won't start")
klog.Errorln("Missing root credentials in the configuration.")
klog.Errorln("MinIO won't start")
os.Exit(1)
}

Expand All @@ -209,12 +209,12 @@ func NewSideCarController(kubeClient *kubernetes.Clientset, controllerClient *cl
func (c *Controller) regenCfg(tenantName string, namespace string, tenantGeneration int64) {
rootUserFound, rootPwdFound, fileContents, err := validator.ReadTmpConfig()
if err != nil {
log.Println(err)
klog.Errorln(err)
return
}
if !rootUserFound || !rootPwdFound {
log.Println("Missing root credentials in the configuration.")
log.Println("MinIO won't start")
klog.Errorln("Missing root credentials in the configuration.")
klog.Errorln("MinIO won't start")
os.Exit(1)
}
c.regenCfgWithCfg(tenantName, namespace, fileContents, tenantGeneration)
Expand All @@ -225,7 +225,7 @@ func (c *Controller) regenCfgWithCfg(tenantName string, namespace string, fileCo

tenant, err := c.controllerClient.MinioV2().Tenants(namespace).Get(ctx, tenantName, metav1.GetOptions{})
if err != nil {
log.Println("could not get tenant", err)
klog.Errorln("could not get tenant", err)
return
}
tenant.EnsureDefaults()
Expand All @@ -234,20 +234,20 @@ func (c *Controller) regenCfgWithCfg(tenantName string, namespace string, fileCo

err = os.WriteFile(v2.CfgFile, []byte(fileContents), 0o644)
if err != nil {
log.Println(err)
klog.Errorln(err)
}
// patch pod annotations
podName := os.Getenv("POD_NAME")
podNamespace := os.Getenv("POD_NAMESPACE")
if podName != "" && podNamespace != "" {
_, err := c.kubeClient.CoreV1().Pods(podNamespace).Patch(ctx, podName, types.MergePatchType, []byte(fmt.Sprintf(`{"metadata":{"annotations":{"%s":"%d"}}}`, common.AnnotationsEnvTenantGeneration, tenantGeneration)), metav1.PatchOptions{})
if err != nil {
log.Printf("failed to patch pod annotations: %s", err)
klog.Errorf("failed to patch pod annotations: %s", err)
} else {
log.Printf("patched pod annotations[%s:%d] succcess", common.AnnotationsEnvTenantGeneration, tenantGeneration)
klog.Infof("patched pod annotations[%s:%d] succcess", common.AnnotationsEnvTenantGeneration, tenantGeneration)
}
} else {
log.Printf("Will not patch for podName[%s] or podNamespace[%s]", podName, podNamespace)
klog.Infof("Will not patch for podName[%s] or podNamespace[%s]", podName, podNamespace)
}
}

Expand Down

0 comments on commit 7196b59

Please sign in to comment.