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

Collect namespaces of deployed resources. #2640

Merged
merged 7 commits into from
Aug 14, 2019

Conversation

tejal29
Copy link
Contributor

@tejal29 tejal29 commented Aug 12, 2019

In #2495, @corneliusweig noticed for a skaffold run without --namespace flag, we make a call for deployment health-check and port-forwarding

client.AppsV1().Deployments(ns).List(metav1.ListOptions{
		LabelSelector: l.K8sManagedByLabelKeyValueString(),
	})

and ns is "".
Similarly, during port-forwarding, we do the same

services, err := clientset.CoreV1().Services("").List(metav1.ListOptions{
		LabelSelector: label,
	})

In context.RunContext, we already gather namespaces set in the kubecontext as well as on command line.
This PR is collect all the namespaces from kubectl manifests and helm releases if they are set individually in the manifests.

This PR is not enough for the bug fix for #2495. We need to followup with a PR where if runcontext.Namespaces is empty, we need to use "default" namespace.

pkg/skaffold/event/event.go Outdated Show resolved Hide resolved
pkg/skaffold/deploy/helm.go Outdated Show resolved Hide resolved
pkg/skaffold/deploy/kubectl.go Show resolved Hide resolved
}
namespaces := make([]string, len(replacer.namespaces))
i := 0
for ns := range replacer.namespaces {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idiomatic way to write this would be

for i, ns := range replacer.namespaces {
  namespaces[i] = ns
}

Copy link
Contributor Author

@tejal29 tejal29 Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is map so its a key value pair.
I will use append. I first thought it allocates a new memory every time and will be inefficient.
But turns out, it only allocates a new memory if the size is less than what was allocated.

namespaces := make([]string, 0, len(replacer.namespaces))

for  ns := range replacer.namespaces {
   namespaces = append(namespaces, ns)
}

pkg/skaffold/deploy/helm.go Outdated Show resolved Hide resolved
pkg/skaffold/runner/notification.go Show resolved Hide resolved
pkg/skaffold/runner/runcontext/context.go Show resolved Hide resolved
@tejal29 tejal29 closed this Aug 12, 2019
@tejal29 tejal29 deleted the collect_namespaces branch August 12, 2019 23:36
@tejal29 tejal29 restored the collect_namespaces branch August 12, 2019 23:37
@tejal29 tejal29 reopened this Aug 12, 2019
@tejal29 tejal29 force-pushed the collect_namespaces branch from adb6e5b to e03a889 Compare August 13, 2019 16:57
@tejal29 tejal29 force-pushed the collect_namespaces branch from e03a889 to adcfede Compare August 13, 2019 17:06
@tejal29 tejal29 force-pushed the collect_namespaces branch from d79853a to 86e8416 Compare August 14, 2019 16:54
@codecov
Copy link

codecov bot commented Aug 14, 2019

Codecov Report

Merging #2640 into master will increase coverage by 0.07%.
The diff coverage is 61.26%.

Impacted Files Coverage Δ
pkg/skaffold/runner/notification.go 0% <0%> (ø) ⬆️
pkg/skaffold/runner/timings.go 14% <0%> (ø) ⬆️
pkg/skaffold/event/event.go 88.59% <0%> (-1.21%) ⬇️
pkg/skaffold/deploy/deploy.go 100% <100%> (ø)
pkg/skaffold/runner/deploy.go 72.22% <100%> (+1.63%) ⬆️
pkg/skaffold/runner/runcontext/context.go 72.09% <100%> (+9.59%) ⬆️
pkg/skaffold/deploy/kustomize.go 72.32% <33.33%> (-1.76%) ⬇️
pkg/skaffold/deploy/kubectl.go 65.51% <35.71%> (-1.45%) ⬇️
pkg/skaffold/deploy/helm.go 66.54% <50%> (-1%) ⬇️
pkg/skaffold/deploy/util.go 78.94% <72.22%> (+10.94%) ⬆️
... and 5 more

Copy link
Contributor

@priyawadhwa priyawadhwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple small comments

pkg/skaffold/deploy/helm.go Outdated Show resolved Hide resolved
return d.namespaces
}

func (d *Result) IsError() (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I feel like I typically see "OK bools" returned as the second argument--

for example, with maps:

val, ok := myMap[key]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants