@@ -35,15 +35,17 @@ import (
3535 corev1 "k8s.io/api/core/v1"
3636 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3737 "k8s.io/apimachinery/pkg/util/wait"
38- "k8s.io/klog"
3938 "sigs.k8s.io/controller-runtime/pkg/client"
39+ logf "sigs.k8s.io/controller-runtime/pkg/log"
4040 "sigs.k8s.io/controller-runtime/pkg/manager"
4141
4242 configv1beta1 "github.com/kubeflow/katib/pkg/apis/config/v1beta1"
4343 "github.com/kubeflow/katib/pkg/controller.v1beta1/consts"
4444)
4545
4646var (
47+ log = logf .Log .WithName ("cert-generator" )
48+
4749 errServiceNotFound = errors .New ("unable to locate controller service" )
4850 errCertCheckFail = errors .New ("failed to check if certs already exist" )
4951 errCreateCertFail = errors .New ("failed to create certs" )
@@ -70,7 +72,7 @@ func (c *CertGenerator) Start(ctx context.Context) error {
7072 if err := c .generate (ctx ); err != nil {
7173 return err
7274 }
73- klog .Info ("Waiting for certs to get ready." )
75+ log .Info ("Waiting for certs to get ready." )
7476 if err := wait .ExponentialBackoffWithContext (ctx , wait.Backoff {
7577 Duration : time .Second ,
7678 Factor : 2 ,
@@ -98,18 +100,18 @@ func ensureCertMounted(start time.Time) func(context.Context) (bool, error) {
98100 certFile := filepath .Join (consts .CertDir , serverCertName )
99101 if _ , err := os .Stat (certFile ); err != nil {
100102 if outputLog {
101- klog . Infof ("Public key file %q doesn't exist in the container yet" , certFile )
103+ log . Info ("Public key file %q doesn't exist in the container yet." , "publicKeyFile " , certFile )
102104 }
103105 return false , nil
104106 }
105107 keyFile := filepath .Join (consts .CertDir , serverKeyName )
106108 if _ , err := os .Stat (keyFile ); err != nil {
107109 if outputLog {
108- klog . Infof ("Private key file %q doesn't exist in the container yet" , keyFile )
110+ log . Info ("Private key file %q doesn't exist in the container yet" , "privateKeyFile " , keyFile )
109111 }
110112 return false , nil
111113 }
112- klog .Info ("Succeeded to be mounted certs inside the container." )
114+ log .Info ("Succeeded to be mounted certs inside the container." )
113115 return true , nil
114116 }
115117}
@@ -196,7 +198,7 @@ func (c *CertGenerator) createCert() error {
196198 ExtKeyUsage : []x509.ExtKeyUsage {x509 .ExtKeyUsageServerAuth },
197199 }
198200
199- klog .Info ("Generating self-signed public certificate and private key." )
201+ log .Info ("Generating self-signed public certificate and private key." )
200202 rawKey , err := rsa .GenerateKey (rand .Reader , 2048 )
201203 if err != nil {
202204 return err
@@ -252,10 +254,10 @@ func (c *CertGenerator) injectCert(ctx context.Context) error {
252254 newVWebhookConfig .Webhooks = vWebhookConfig .Webhooks
253255 newVWebhookConfig .Webhooks [0 ].ClientConfig .CABundle = c .certs .certPem
254256
255- klog .Info ("Trying to patch ValidatingWebhookConfiguration adding the caBundle." )
257+ log .Info ("Trying to patch ValidatingWebhookConfiguration adding the caBundle." )
256258 err := c .kubeClient .Patch (ctx , newVWebhookConfig , client .Apply , client .FieldOwner (ssaFieldOwnerName ), client .ForceOwnership )
257259 if err != nil {
258- klog . Errorf ( "Unable to patch ValidatingWebhookConfiguration %q " , Webhook )
260+ log . Error ( err , "Unable to patch ValidatingWebhookConfiguration" , "ValidatingWebhookConfiguration " , Webhook )
259261 return err
260262 }
261263 }
@@ -279,10 +281,10 @@ func (c *CertGenerator) injectCert(ctx context.Context) error {
279281 newMWebhookConfig .Webhooks [0 ].ClientConfig .CABundle = c .certs .certPem
280282 newMWebhookConfig .Webhooks [1 ].ClientConfig .CABundle = c .certs .certPem
281283
282- klog .Info ("Trying to patch MutatingWebhookConfiguration adding the caBundle." )
284+ log .Info ("Trying to patch MutatingWebhookConfiguration adding the caBundle." )
283285 err := c .kubeClient .Patch (ctx , newMWebhookConfig , client .Apply , client .FieldOwner (ssaFieldOwnerName ), client .ForceOwnership )
284286 if err != nil {
285- klog . Errorf ( "Unable to patch MutatingWebhookConfiguration %q " , Webhook )
287+ log . Error ( err , "Unable to patch MutatingWebhookConfiguration" , "MutatingWebhookConfiguration " , Webhook )
286288 return err
287289 }
288290 }
0 commit comments