Skip to content

Commit

Permalink
Avoid aliasing in image configuration (#5804)
Browse files Browse the repository at this point in the history
* Avoid aliasing in image configuration

* pacify golangci-lint
  • Loading branch information
briandealwis committed May 12, 2021
1 parent 2f3ed37 commit c0c01f0
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pkg/skaffold/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ func retrieveImageConfiguration(ctx context.Context, artifact *graph.Artifact, i

config := manifest.Config
logrus.Debugf("Retrieved local image configuration for %v: %v", artifact.Tag, config)
// need to duplicate slices as apiClient caches requests
return imageConfiguration{
artifact: artifact.ImageName,
env: envAsMap(config.Env),
entrypoint: config.Entrypoint,
arguments: config.Cmd,
labels: config.Labels,
entrypoint: dupArray(config.Entrypoint),
arguments: dupArray(config.Cmd),
labels: dupMap(config.Labels),
workingDir: config.WorkingDir,
}, nil
}
Expand All @@ -138,3 +139,23 @@ func envAsMap(env []string) map[string]string {
}
return result
}

func dupArray(s []string) []string {
if len(s) == 0 {
return nil
}
dup := make([]string, len(s))
copy(dup, s)
return dup
}

func dupMap(s map[string]string) map[string]string {
if len(s) == 0 {
return nil
}
dup := make(map[string]string, len(s))
for k, v := range s {
dup[k] = v
}
return dup
}

0 comments on commit c0c01f0

Please sign in to comment.