@@ -24,6 +24,7 @@ import (
24
24
25
25
"github.com/OpenFunction/cli/pkg/cmd/util"
26
26
cc "github.com/OpenFunction/cli/pkg/cmd/util/client"
27
+ openfunction "github.com/openfunction/apis/core/v1beta1"
27
28
client "github.com/openfunction/pkg/client/clientset/versioned"
28
29
swclient "github.com/shipwright-io/build/pkg/client/clientset/versioned"
29
30
"github.com/spf13/cobra"
@@ -121,48 +122,48 @@ func (l *Logs) run() error {
121
122
}
122
123
123
124
// Build stage
124
- if f .Status .Build != nil {
125
+ if f .Status .Build != nil && f . Status . Build . State != openfunction . Skipped {
125
126
builderRef := f .Status .Build .ResourceRef
126
-
127
- // get openfunction builder ref
128
- builder , err := l .functionClient .CoreV1beta1 ().Builders (f .Namespace ).Get (ctx , builderRef , metav1.GetOptions {})
129
- if err != nil {
130
- statusError , ok := err .(* k8serrors.StatusError )
131
- // builder has been cleaned up
132
- if ! ok || statusError .Status ().Code != 404 {
133
- return err
134
- }
135
- }
136
-
137
- // get shipwright builder-buildrun
138
- swbuildrunRef := builder .Status .ResourceRef ["shipwright.io/buildRun" ]
139
- if swbuildrunRef != "" {
140
- swBuildRun , err := l .swClient .ShipwrightV1alpha1 ().BuildRuns (f .Namespace ).Get (ctx , swbuildrunRef , metav1.GetOptions {})
127
+ if builderRef != "" {
128
+ // get openfunction builder ref
129
+ builder , err := l .functionClient .CoreV1beta1 ().Builders (f .Namespace ).Get (ctx , builderRef , metav1.GetOptions {})
141
130
if err != nil {
142
131
statusError , ok := err .(* k8serrors.StatusError )
143
- // buildrun has been cleaned up
132
+ // builder has been cleaned up
144
133
if ! ok || statusError .Status ().Code != 404 {
145
134
return err
146
135
}
147
136
}
148
- err = l .logsForPods (ctx , metav1.ListOptions {LabelSelector : fmt .Sprintf ("buildrun.shipwright.io/name=%s" , swBuildRun .Name )})
149
- if err != nil {
150
- return err
137
+ // get shipwright builder-buildrun
138
+ swbuildrunRef := builder .Status .ResourceRef ["shipwright.io/buildRun" ]
139
+ if swbuildrunRef != "" {
140
+ swBuildRun , err := l .swClient .ShipwrightV1alpha1 ().BuildRuns (f .Namespace ).Get (ctx , swbuildrunRef , metav1.GetOptions {})
141
+ if err != nil {
142
+ statusError , ok := err .(* k8serrors.StatusError )
143
+ // buildrun has been cleaned up
144
+ if ! ok || statusError .Status ().Code != 404 {
145
+ return err
146
+ }
147
+ }
148
+ err = l .logsForPods (ctx , metav1.ListOptions {LabelSelector : fmt .Sprintf ("buildrun.shipwright.io/name=%s" , swBuildRun .Name )})
149
+ if err != nil {
150
+ return err
151
+ }
151
152
}
152
153
}
153
-
154
154
}
155
155
156
156
// Serving stage
157
- if f .Status .Serving != nil {
158
- serving := f .Status .Serving .ResourceRef
159
-
160
- if l .containerName == "" {
161
- l .containerName = "function"
162
- }
163
- err := l .logsForPods (ctx , metav1.ListOptions {LabelSelector : fmt .Sprintf ("openfunction.io/serving=%s" , serving )})
164
- if err != nil {
165
- return err
157
+ if f .Status .Serving != nil && f .Status .Serving .State != openfunction .Skipped {
158
+ servingRef := f .Status .Serving .ResourceRef
159
+ if servingRef != "" {
160
+ if l .containerName == "" {
161
+ l .containerName = "function"
162
+ }
163
+ err := l .logsForPods (ctx , metav1.ListOptions {LabelSelector : fmt .Sprintf ("openfunction.io/serving=%s" , servingRef )})
164
+ if err != nil {
165
+ return err
166
+ }
166
167
}
167
168
}
168
169
@@ -183,15 +184,17 @@ func (l *Logs) logsForPods(ctx context.Context, listOpt metav1.ListOptions) erro
183
184
var logReader io.ReadCloser
184
185
if l .containerName != "" {
185
186
logReader , err = podInterface .GetLogs (pod .Name , & corev1.PodLogOptions {Follow : l .Follow , Container : l .containerName }).Stream (ctx )
186
- if err != nil {
187
+ // the pod may be deleted due to scale, so we should exclude NotFound errors
188
+ if err != nil && ! k8serrors .IsNotFound (err ) {
187
189
return err
188
190
}
189
191
defer logReader .Close ()
190
192
readerList = append (readerList , logReader )
191
193
} else {
192
194
for _ , container := range pod .Spec .Containers {
193
195
logReader , err = podInterface .GetLogs (pod .Name , & corev1.PodLogOptions {Follow : l .Follow , Container : container .Name }).Stream (ctx )
194
- if err != nil {
196
+ // the pod may be deleted due to scale, so we should exclude NotFound errors
197
+ if err != nil && ! k8serrors .IsNotFound (err ) {
195
198
return err
196
199
}
197
200
0 commit comments