@@ -35,15 +35,17 @@ import (
35
35
corev1 "k8s.io/api/core/v1"
36
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
37
37
"k8s.io/apimachinery/pkg/util/wait"
38
- "k8s.io/klog"
39
38
"sigs.k8s.io/controller-runtime/pkg/client"
39
+ logf "sigs.k8s.io/controller-runtime/pkg/log"
40
40
"sigs.k8s.io/controller-runtime/pkg/manager"
41
41
42
42
configv1beta1 "github.com/kubeflow/katib/pkg/apis/config/v1beta1"
43
43
"github.com/kubeflow/katib/pkg/controller.v1beta1/consts"
44
44
)
45
45
46
46
var (
47
+ log = logf .Log .WithName ("cert-generator" )
48
+
47
49
errServiceNotFound = errors .New ("unable to locate controller service" )
48
50
errCertCheckFail = errors .New ("failed to check if certs already exist" )
49
51
errCreateCertFail = errors .New ("failed to create certs" )
@@ -70,7 +72,7 @@ func (c *CertGenerator) Start(ctx context.Context) error {
70
72
if err := c .generate (ctx ); err != nil {
71
73
return err
72
74
}
73
- klog .Info ("Waiting for certs to get ready." )
75
+ log .Info ("Waiting for certs to get ready." )
74
76
if err := wait .ExponentialBackoffWithContext (ctx , wait.Backoff {
75
77
Duration : time .Second ,
76
78
Factor : 2 ,
@@ -98,18 +100,18 @@ func ensureCertMounted(start time.Time) func(context.Context) (bool, error) {
98
100
certFile := filepath .Join (consts .CertDir , serverCertName )
99
101
if _ , err := os .Stat (certFile ); err != nil {
100
102
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 )
102
104
}
103
105
return false , nil
104
106
}
105
107
keyFile := filepath .Join (consts .CertDir , serverKeyName )
106
108
if _ , err := os .Stat (keyFile ); err != nil {
107
109
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 )
109
111
}
110
112
return false , nil
111
113
}
112
- klog .Info ("Succeeded to be mounted certs inside the container." )
114
+ log .Info ("Succeeded to be mounted certs inside the container." )
113
115
return true , nil
114
116
}
115
117
}
@@ -196,7 +198,7 @@ func (c *CertGenerator) createCert() error {
196
198
ExtKeyUsage : []x509.ExtKeyUsage {x509 .ExtKeyUsageServerAuth },
197
199
}
198
200
199
- klog .Info ("Generating self-signed public certificate and private key." )
201
+ log .Info ("Generating self-signed public certificate and private key." )
200
202
rawKey , err := rsa .GenerateKey (rand .Reader , 2048 )
201
203
if err != nil {
202
204
return err
@@ -252,10 +254,10 @@ func (c *CertGenerator) injectCert(ctx context.Context) error {
252
254
newVWebhookConfig .Webhooks = vWebhookConfig .Webhooks
253
255
newVWebhookConfig .Webhooks [0 ].ClientConfig .CABundle = c .certs .certPem
254
256
255
- klog .Info ("Trying to patch ValidatingWebhookConfiguration adding the caBundle." )
257
+ log .Info ("Trying to patch ValidatingWebhookConfiguration adding the caBundle." )
256
258
err := c .kubeClient .Patch (ctx , newVWebhookConfig , client .Apply , client .FieldOwner (ssaFieldOwnerName ), client .ForceOwnership )
257
259
if err != nil {
258
- klog . Errorf ( "Unable to patch ValidatingWebhookConfiguration %q " , Webhook )
260
+ log . Error ( err , "Unable to patch ValidatingWebhookConfiguration" , "ValidatingWebhookConfiguration " , Webhook )
259
261
return err
260
262
}
261
263
}
@@ -279,10 +281,10 @@ func (c *CertGenerator) injectCert(ctx context.Context) error {
279
281
newMWebhookConfig .Webhooks [0 ].ClientConfig .CABundle = c .certs .certPem
280
282
newMWebhookConfig .Webhooks [1 ].ClientConfig .CABundle = c .certs .certPem
281
283
282
- klog .Info ("Trying to patch MutatingWebhookConfiguration adding the caBundle." )
284
+ log .Info ("Trying to patch MutatingWebhookConfiguration adding the caBundle." )
283
285
err := c .kubeClient .Patch (ctx , newMWebhookConfig , client .Apply , client .FieldOwner (ssaFieldOwnerName ), client .ForceOwnership )
284
286
if err != nil {
285
- klog . Errorf ( "Unable to patch MutatingWebhookConfiguration %q " , Webhook )
287
+ log . Error ( err , "Unable to patch MutatingWebhookConfiguration" , "MutatingWebhookConfiguration " , Webhook )
286
288
return err
287
289
}
288
290
}
0 commit comments