Skip to content

Commit b28c63a

Browse files
committed
fix: ensure run-id is added to resources in skaffold apply; remove --add-skaffold-labels
1 parent f15f502 commit b28c63a

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

cmd/skaffold/app/cmd/flags.go

-13
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,6 @@ var flagRegistry = []Flag{
470470
FlagAddMethod: "IntVar",
471471
DefinedOn: []string{"dev", "debug"},
472472
},
473-
{
474-
Name: "add-skaffold-labels",
475-
Usage: "Add Skaffold-specific labels to rendered manifest. Custom labels will still be applied. Helpful for GitOps model where Skaffold is not the deployer.",
476-
Value: &opts.AddSkaffoldLabels,
477-
DefValue: true,
478-
DefValuePerCommand: map[string]interface{}{
479-
"render": false,
480-
},
481-
FlagAddMethod: "BoolVar",
482-
DefinedOn: []string{"dev", "debug", "render", "run"},
483-
IsEnum: true,
484-
Deprecated: "Adding Skaffold-specific labels in `render` is deprecated.",
485-
},
486473
{
487474
Name: "mute-logs",
488475
Usage: "mute logs for specified stages in pipeline (build, deploy, status-check, none, all)",

integration/apply_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ func TestRenderApplyHelmDeployment(t *testing.T) {
7575
t.CheckNotNil(depApp)
7676
})
7777
}
78+
79+
// Ensure that an intentionally broken deployment fails the status check in `skaffold apply`.
80+
func TestApplyStatusCheckFailure(t *testing.T) {
81+
testutil.Run(t, "ApplyStatusCheckFailure", func(t *testutil.T) {
82+
err := skaffold.Apply("deployment.yaml").InDir("testdata/apply").Run(t.T)
83+
84+
t.CheckError(true, err)
85+
})
86+
}

integration/render_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ spec:
246246
},
247247
},
248248
}}),
249-
Opts: config.SkaffoldOptions{
250-
AddSkaffoldLabels: true,
251-
},
249+
Opts: config.SkaffoldOptions{},
252250
}, &label.DefaultLabeller{}, &latestV1.KubectlDeploy{
253251
Manifests: []string{"deployment.yaml"},
254252
})
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: zz-image-doesnt-exist
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: apply-status-check-failure
10+
template:
11+
metadata:
12+
labels:
13+
app: apply-status-check-failure
14+
spec:
15+
containers:
16+
- image: zz-image-doesnt-exist
17+
name: apply-status-check-failure
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apiVersion: skaffold/v2beta24
2+
kind: Config

pkg/skaffold/config/options.go

+20-25
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,26 @@ type SkaffoldOptions struct {
7373
SkipRender bool
7474
SkipConfigDefaults bool
7575
PropagateProfiles bool
76-
// Add Skaffold-specific labels including runID, deployer labels, etc.
77-
// `CustomLabels` are still applied if this is false. Must only be used in
78-
// commands which don't deploy (e.g. `skaffold render`) since the runID
79-
// label isn't available.
80-
AddSkaffoldLabels bool
81-
DetectMinikube bool
82-
IterativeStatusCheck bool
83-
ForceLoadImages bool
84-
WaitForConnection bool
85-
MakePathsAbsolute *bool
86-
StatusCheck BoolOrUndefined
87-
PortForward PortForwardOptions
88-
DefaultRepo StringOrUndefined
89-
PushImages BoolOrUndefined
90-
CustomLabels []string
91-
TargetImages []string
92-
Profiles []string
93-
InsecureRegistries []string
94-
ConfigurationFilter []string
95-
HydratedManifests []string
96-
Muted Muted
97-
BuildConcurrency int
98-
WatchPollInterval int
99-
RPCPort IntOrUndefined
100-
RPCHTTPPort IntOrUndefined
76+
DetectMinikube bool
77+
IterativeStatusCheck bool
78+
ForceLoadImages bool
79+
WaitForConnection bool
80+
MakePathsAbsolute *bool
81+
StatusCheck BoolOrUndefined
82+
PortForward PortForwardOptions
83+
DefaultRepo StringOrUndefined
84+
PushImages BoolOrUndefined
85+
CustomLabels []string
86+
TargetImages []string
87+
Profiles []string
88+
InsecureRegistries []string
89+
ConfigurationFilter []string
90+
HydratedManifests []string
91+
Muted Muted
92+
BuildConcurrency int
93+
WatchPollInterval int
94+
RPCPort IntOrUndefined
95+
RPCHTTPPort IntOrUndefined
10196

10297
SyncRemoteCache SyncRemoteCacheOption
10398
WaitForDeletions WaitForDeletions

pkg/skaffold/runner/runcontext/context.go

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ func (rc *RunContext) GetInsecureRegistries() map[string]bool { return rc
173173
func (rc *RunContext) GetWorkingDir() string { return rc.WorkingDir }
174174
func (rc *RunContext) GetCluster() config.Cluster { return rc.Cluster }
175175
func (rc *RunContext) GetNamespace() string { return rc.Opts.Namespace }
176-
func (rc *RunContext) AddSkaffoldLabels() bool { return rc.Opts.AddSkaffoldLabels }
177176
func (rc *RunContext) AutoBuild() bool { return rc.Opts.AutoBuild }
178177
func (rc *RunContext) AutoDeploy() bool { return rc.Opts.AutoDeploy }
179178
func (rc *RunContext) AutoSync() bool { return rc.Opts.AutoSync }

pkg/skaffold/runner/v1/new.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
2424
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/cache"
25+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
2526
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy"
2627
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy/label"
2728
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
@@ -61,7 +62,9 @@ func NewForConfig(ctx context.Context, runCtx *runcontext.RunContext) (*Skaffold
6162
isLocalImage := func(imageName string) (bool, error) {
6263
return isImageLocal(runCtx, imageName)
6364
}
64-
labeller := label.NewLabeller(runCtx.AddSkaffoldLabels(), runCtx.CustomLabels(), runCtx.GetRunID())
65+
66+
// Always add skaffold-specific labels, except during `skaffold render`
67+
labeller := label.NewLabeller(runCtx.Mode() != config.RunModes.Render, runCtx.CustomLabels(), runCtx.GetRunID())
6568
tester, err := getTester(ctx, runCtx, isLocalImage)
6669
if err != nil {
6770
endTrace(instrumentation.TraceEndError(err))

0 commit comments

Comments
 (0)