Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update labels when deploying to namespace other than default #1115

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func AddRunDevFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file")
cmd.Flags().BoolVar(&opts.Notification, "toot", false, "Emit a terminal beep after the deploy is complete")
cmd.Flags().StringArrayVarP(&opts.Profiles, "profile", "p", nil, "Activate profiles by name")
cmd.Flags().StringVarP(&opts.Namespace, "namespace", "n", "", "Run Helm deployments in the specified namespace")
cmd.Flags().StringVarP(&opts.Namespace, "namespace", "n", "", "Run deployments in the specified namespace")
}

func AddFixFlags(cmd *cobra.Command) {
Expand Down
10 changes: 6 additions & 4 deletions pkg/skaffold/deploy/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (k *KubectlDeployer) Deploy(ctx context.Context, out io.Writer, builds []bu
return nil, errors.Wrap(err, "apply")
}

return parseManifestsForDeploys(updated)
return parseManifestsForDeploys(k.kubectl.Namespace, updated)
}

// Cleanup deletes what was deployed by calling Deploy.
Expand Down Expand Up @@ -128,12 +128,14 @@ func (k *KubectlDeployer) manifestFiles(manifests []string) ([]string, error) {
return filteredManifests, nil
}

func parseManifestsForDeploys(manifests kubectl.ManifestList) ([]Artifact, error) {
results := []Artifact{}
func parseManifestsForDeploys(namespace string, manifests kubectl.ManifestList) ([]Artifact, error) {
var results []Artifact

for _, manifest := range manifests {
b := bufio.NewReader(bytes.NewReader(manifest))
results = append(results, parseReleaseInfo("", b)...)
results = append(results, parseReleaseInfo(namespace, b)...)
}

return results, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (k *KustomizeDeployer) Deploy(ctx context.Context, out io.Writer, builds []
return nil, errors.Wrap(err, "apply")
}

return parseManifestsForDeploys(updated)
return parseManifestsForDeploys(k.kubectl.Namespace, updated)
}

// Cleanup deletes what was deployed by calling Deploy.
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/deploy/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ func updateRuntimeObject(client dynamic.Interface, disco discovery.DiscoveryInte
if err != nil {
return errors.Wrap(err, "getting group version resource from obj")
}

ns, err := resolveNamespace(namespace)
if err != nil {
return errors.Wrap(err, "resolving namespace")
}
logrus.Debugln("Patching", name, "in namespace", ns)

if _, err := client.Resource(gvr).Namespace(ns).Patch(name, types.StrategicMergePatchType, p); err != nil {
return errors.Wrapf(err, "patching resource %s/%s", namespace, name)
}
Expand Down