Skip to content

Commit d0178a3

Browse files
committed
print debug in k8s
1 parent 634ce9d commit d0178a3

File tree

1 file changed

+66
-32
lines changed

1 file changed

+66
-32
lines changed

lib/k8s/environment/runner.go

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package environment
22

33
import (
44
"bytes"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"strconv"
@@ -237,19 +238,35 @@ func role(chart cdk8s.Chart, props *Props) {
237238
}
238239

239240
func kubeSecret(chart cdk8s.Chart, props *Props) {
241+
secretProps := &k8s.KubeSecretProps{
242+
Metadata: &k8s.ObjectMeta{
243+
Name: ptr.Ptr("ts-secret"),
244+
Labels: props.Labels,
245+
},
246+
Type: ptr.Ptr("Opaque"), // Typical for storing arbitrary user-defined data
247+
StringData: &map[string]*string{
248+
".testsecrets": ptr.Ptr(createTestSecretsDotenvFromEnvVars()),
249+
},
250+
}
251+
252+
propsJSON, err := json.MarshalIndent(secretProps, "", " ")
253+
if err != nil {
254+
log.Error().Err(err).Msg("Failed to marshal secretProps")
255+
} else {
256+
log.Debug().Msgf("SecretProps: %s", propsJSON)
257+
}
258+
259+
chartJson, err := json.MarshalIndent(chart.ToJson(), "", " ")
260+
if err != nil {
261+
log.Error().Err(err).Msg("Failed to marshal chart")
262+
} else {
263+
log.Debug().Msgf("Chart: %s", chartJson)
264+
}
265+
240266
k8s.NewKubeSecret(
241267
chart,
242268
ptr.Ptr("ts-secret"),
243-
&k8s.KubeSecretProps{
244-
Metadata: &k8s.ObjectMeta{
245-
Name: ptr.Ptr("ts-secret"),
246-
Labels: props.Labels,
247-
},
248-
Type: ptr.Ptr("Opaque"), // Typical for storing arbitrary user-defined data
249-
StringData: &map[string]*string{
250-
".testsecrets": ptr.Ptr(createTestSecretsDotenvFromEnvVars()),
251-
},
252-
},
269+
secretProps,
253270
)
254271
}
255272

@@ -282,31 +299,48 @@ func job(chart cdk8s.Chart, props *Props) {
282299
SecretName: ptr.Ptr("ts-secret"),
283300
},
284301
})
302+
303+
jobProps := &k8s.KubeJobProps{
304+
Metadata: &k8s.ObjectMeta{
305+
Name: ptr.Ptr(props.BaseName),
306+
Labels: props.Labels,
307+
},
308+
Spec: &k8s.JobSpec{
309+
Template: &k8s.PodTemplateSpec{
310+
Metadata: &k8s.ObjectMeta{
311+
Labels: props.Labels,
312+
Annotations: a.ConvertAnnotations(defaultRunnerPodAnnotations),
313+
},
314+
Spec: &k8s.PodSpec{
315+
ServiceAccountName: ptr.Ptr("default"),
316+
Containers: container(props),
317+
RestartPolicy: ptr.Ptr(restartPolicy),
318+
Volumes: &volumes,
319+
},
320+
},
321+
ActiveDeadlineSeconds: nil,
322+
BackoffLimit: ptr.Ptr(backOffLimit),
323+
},
324+
}
325+
326+
propsJSON, err := json.MarshalIndent(jobProps, "", " ")
327+
if err != nil {
328+
log.Error().Err(err).Msg("Failed to marshal secretProps")
329+
} else {
330+
log.Debug().Msgf("SecretProps: %s", propsJSON)
331+
}
332+
333+
chartJson, err := json.MarshalIndent(chart.ToJson(), "", " ")
334+
if err != nil {
335+
log.Error().Err(err).Msg("Failed to marshal chart")
336+
} else {
337+
log.Debug().Msgf("Chart: %s", chartJson)
338+
}
339+
285340
k8s.NewKubeJob(
286341
chart,
287342
ptr.Ptr(fmt.Sprintf("%s-job", props.BaseName)),
288-
&k8s.KubeJobProps{
289-
Metadata: &k8s.ObjectMeta{
290-
Name: ptr.Ptr(props.BaseName),
291-
Labels: props.Labels,
292-
},
293-
Spec: &k8s.JobSpec{
294-
Template: &k8s.PodTemplateSpec{
295-
Metadata: &k8s.ObjectMeta{
296-
Labels: props.Labels,
297-
Annotations: a.ConvertAnnotations(defaultRunnerPodAnnotations),
298-
},
299-
Spec: &k8s.PodSpec{
300-
ServiceAccountName: ptr.Ptr("default"),
301-
Containers: container(props),
302-
RestartPolicy: ptr.Ptr(restartPolicy),
303-
Volumes: &volumes,
304-
},
305-
},
306-
ActiveDeadlineSeconds: nil,
307-
BackoffLimit: ptr.Ptr(backOffLimit),
308-
},
309-
})
343+
jobProps)
310344
}
311345

312346
func container(props *Props) *[]*k8s.Container {

0 commit comments

Comments
 (0)