Skip to content

Commit e7077c1

Browse files
Testing to figure out stack log issues (#554)
recent release is suppressing all log output from stack runs, trying to debug here
1 parent 4089cbc commit e7077c1

File tree

5 files changed

+29
-51
lines changed

5 files changed

+29
-51
lines changed

pkg/controller/service/reconciler_status.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/log"
1717
)
1818

19+
const (
20+
ignoreSha = "__ignore__"
21+
)
22+
1923
func (s *ServiceReconciler) UpdateErrorStatus(ctx context.Context, id string, err error) {
2024
if err := s.UpdateErrors(id, errorAttributes("sync", err)); err != nil {
2125
log.FromContext(ctx).Error(err, "Failed to update service status, ignoring for now")
@@ -59,21 +63,23 @@ func (s *ServiceReconciler) UpdateStatus(ctx context.Context, id, revisionID str
5963
// hash the components and errors to determine if there has been a meaningful change
6064
// we need to report to the server
6165
objToHash := struct {
62-
Components []*console.ComponentAttributes `json:"components"`
63-
Errs []*console.ServiceErrorAttributes `json:"errs"`
64-
RevisionID string `json:"revisionId"`
65-
Sha *string `json:"sha,omitempty"`
66+
Components []*console.ComponentAttributes `json:"components"`
67+
Errs []*console.ServiceErrorAttributes `json:"errs"`
68+
RevisionID string `json:"revisionId"`
69+
Sha *string `json:"sha,omitempty"`
70+
Metadata *console.ServiceMetadataAttributes `json:"metadata,omitempty"`
6671
}{
6772
Components: components,
6873
Errs: errs,
6974
RevisionID: revisionID,
7075
Sha: sha,
76+
Metadata: metadata,
7177
}
7278

7379
hashedSha, err := utils.HashObject(objToHash)
7480
if err != nil {
7581
log.Log.Error(err, "Failed to hash service components")
76-
hashedSha = "__ignore__"
82+
hashedSha = ignoreSha
7783
}
7884

7985
logger := log.FromContext(ctx).V(int(plrlog.LogLevelDefault))
@@ -85,7 +91,7 @@ func (s *ServiceReconciler) UpdateStatus(ctx context.Context, id, revisionID str
8591
return nil
8692
}
8793

88-
if hashedSha != "__ignore__" {
94+
if hashedSha != ignoreSha {
8995
shaCache.Add(id, hashedSha)
9096
}
9197

pkg/harness/controller/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func (in *stackRunController) toExecutable(ctx context.Context, step *gqlclient.
107107
modifier := in.tool.Modifier(step.Stage)
108108
args := step.Args
109109
env := in.stackRun.Env()
110+
110111
consoleWriter := sink.NewConsoleWriter(
111112
ctx,
112113
in.consoleClient,

pkg/harness/exec/exec.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func (in *executable) Run(ctx context.Context) error {
2424
if err != nil {
2525
return err
2626
}
27+
defer in.close(in.outputSinks)
2728

2829
klog.V(log.LogLevelExtended).InfoS("executing", "command", in.Command())
2930
if err = cmd.Run(); err != nil {
@@ -51,7 +52,12 @@ func (in *executable) Start(ctx context.Context) (WaitFn, error) {
5152
return nil, err
5253
}
5354

54-
return cmd.Wait, in.runLifecycleFunction(v1.LifecyclePostStart)
55+
waiter := func() error {
56+
defer in.close(in.outputSinks)
57+
return cmd.Wait()
58+
}
59+
60+
return waiter, in.runLifecycleFunction(v1.LifecyclePostStart)
5561
}
5662

5763
func (in *executable) RunWithOutput(ctx context.Context) ([]byte, error) {
@@ -91,7 +97,6 @@ func (in *executable) prepare(ctx context.Context) (*exec.Cmd, error) {
9197
ctx = signals.NewCancelableContext(ctx, signals.NewTimeoutSignal(in.timeout))
9298
cmd := exec.CommandContext(ctx, in.command, in.args...)
9399
w := in.writer()
94-
defer in.close(in.outputSinks)
95100

96101
// Configure additional writers so that we can simultaneously write output
97102
// to multiple destinations

pkg/harness/tool/v1/modifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (in *DefaultModifier) Args(args []string) []string {
1111

1212
// WriteCloser implements [PassthroughModifier] interface.
1313
func (in *DefaultModifier) WriteCloser() []io.WriteCloser {
14-
return nil
14+
return make([]io.WriteCloser, 0)
1515
}
1616

1717
// Env implements [EnvModifier] interface.

pkg/metadata/extractor.go

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"strings"
55

66
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
7-
"k8s.io/klog/v2"
87
)
98

109
func ExtractImagesFromResource(resource *unstructured.Unstructured) []string {
@@ -13,39 +12,24 @@ func ExtractImagesFromResource(resource *unstructured.Unstructured) []string {
1312
}
1413

1514
kind := strings.ToLower(resource.GetKind())
16-
ns, name := resource.GetNamespace(), resource.GetName()
1715
var out []string
1816

1917
switch kind {
2018
case "deployment", "statefulset", "daemonset", "replicaset":
21-
if found, imgs, err := extractImagesFromPath(resource, "spec", "template", "spec", "containers"); err != nil {
22-
klog.Warningf("failed to extract containers from %s %s/%s: %v", resource.GetKind(), ns, name, err)
23-
return nil
24-
} else if !found {
25-
return nil
26-
} else {
19+
if found, imgs, err := extractImagesFromPath(resource, "spec", "template", "spec", "containers"); err == nil && found {
2720
out = append(out, imgs...)
2821
}
2922

30-
if _, imgs, err := extractImagesFromPath(resource, "spec", "template", "spec", "initContainers"); err != nil {
31-
klog.Infof("Error extracting init containers from %s %s/%s: %v", resource.GetKind(), ns, name, err)
32-
} else {
23+
if found, imgs, err := extractImagesFromPath(resource, "spec", "template", "spec", "initContainers"); err == nil && found {
3324
out = append(out, imgs...)
3425
}
3526

3627
case "pod":
37-
if found, imgs, err := extractImagesFromPath(resource, "spec", "containers"); err != nil {
38-
klog.Warningf("failed to extract containers from pod %s/%s: %v", ns, name, err)
39-
return nil
40-
} else if !found {
41-
return nil
42-
} else {
28+
if found, imgs, err := extractImagesFromPath(resource, "spec", "containers"); err == nil && found {
4329
out = append(out, imgs...)
4430
}
4531

46-
if _, imgs, err := extractImagesFromPath(resource, "spec", "initContainers"); err != nil {
47-
klog.Infof("Error extracting init containers from Pod %s/%s: %v", ns, name, err)
48-
} else {
32+
if found, imgs, err := extractImagesFromPath(resource, "spec", "initContainers"); err == nil && found {
4933
out = append(out, imgs...)
5034
}
5135
}
@@ -116,11 +100,7 @@ func (f *fqdnSet) result() []string {
116100
}
117101

118102
func extractIngressFQDNs(u *unstructured.Unstructured, add func(string)) {
119-
ns, name := u.GetNamespace(), u.GetName()
120-
121-
if rules, found, err := unstructured.NestedSlice(u.Object, "spec", "rules"); err != nil {
122-
logExtractErr("Ingress", ns, name, "rules", err)
123-
} else if found {
103+
if rules, found, err := unstructured.NestedSlice(u.Object, "spec", "rules"); err == nil && found {
124104
for _, r := range rules {
125105
if m, ok := r.(map[string]interface{}); ok {
126106
if host, ok := m["host"].(string); ok {
@@ -130,9 +110,7 @@ func extractIngressFQDNs(u *unstructured.Unstructured, add func(string)) {
130110
}
131111
}
132112

133-
if tls, found, err := unstructured.NestedSlice(u.Object, "spec", "tls"); err != nil {
134-
logExtractErr("Ingress", ns, name, "tls", err)
135-
} else if found {
113+
if tls, found, err := unstructured.NestedSlice(u.Object, "spec", "tls"); err == nil && found {
136114
for _, t := range tls {
137115
m, ok := t.(map[string]interface{})
138116
if !ok {
@@ -150,11 +128,7 @@ func extractIngressFQDNs(u *unstructured.Unstructured, add func(string)) {
150128
}
151129

152130
func extractHTTPRouteFQDNs(u *unstructured.Unstructured, add func(string)) {
153-
ns, name, kind := u.GetNamespace(), u.GetName(), u.GetKind()
154-
155-
if hn, found, err := unstructured.NestedSlice(u.Object, "spec", "hostnames"); err != nil {
156-
logExtractErr(kind, ns, name, "hostnames", err)
157-
} else if found {
131+
if hn, found, err := unstructured.NestedSlice(u.Object, "spec", "hostnames"); err == nil && found {
158132
for _, h := range hn {
159133
if s, ok := h.(string); ok {
160134
add(s)
@@ -164,11 +138,7 @@ func extractHTTPRouteFQDNs(u *unstructured.Unstructured, add func(string)) {
164138
}
165139

166140
func extractGatewayFQDNs(u *unstructured.Unstructured, add func(string)) {
167-
ns, name := u.GetNamespace(), u.GetName()
168-
169-
if listeners, found, err := unstructured.NestedSlice(u.Object, "spec", "listeners"); err != nil {
170-
logExtractErr("Gateway", ns, name, "listeners", err)
171-
} else if found {
141+
if listeners, found, err := unstructured.NestedSlice(u.Object, "spec", "listeners"); err == nil && found {
172142
for _, l := range listeners {
173143
if m, ok := l.(map[string]interface{}); ok {
174144
if s, ok := m["hostname"].(string); ok {
@@ -178,7 +148,3 @@ func extractGatewayFQDNs(u *unstructured.Unstructured, add func(string)) {
178148
}
179149
}
180150
}
181-
182-
func logExtractErr(kind, ns, name, field string, err error) {
183-
klog.Infof("Error extracting %s from %s %s/%s: %v", field, kind, ns, name, err)
184-
}

0 commit comments

Comments
 (0)