Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

refactor namespace to kind of target #173

Merged
merged 6 commits into from
Mar 19, 2020

Conversation

neo-liang-sap
Copy link
Contributor

@neo-liang-sap neo-liang-sap commented Mar 16, 2020

What this PR does / why we need it:
This PR makes namespace to be one kind of target, just like garden/seed/project/shoot

Which issue(s) this PR fixes:
Fixes # #169

Special notes for your reviewer:

  • gardenctl ls namespace is supported
  • i've tested in following scenario/combination
gardenctl target -g canary-virtual -s gcp-eu2 -p everest -t ev-1373-b -n kube-system
gardenctl target -g canary-virtual -s gcp-eu2 -p everest -n kube-system
gardenctl target -g canary-virtual -s gcp-eu2 -n kube-system
gardenctl target -g canary-virtual -n kube-system
gardenctl target -s gcp-eu2 -p everest -t ev-1373-b -n kube-system
gardenctl target -s gcp-eu2 -t ev-1373-b -n kube-system
gardenctl target -s gcp-eu2 -n kube-system
gardenctl target -p everest -t ev-1373-b -n kube-system
gardenctl target -p everest -n kube-system
gardenctl target -n kube-system

gardenctl target -g canary-virtual -p everest -t ev-1373-b -n kube-system
gardenctl target -g canary-virtual -p everest -n kube-system
gardenctl target -g canary-virtual -t ev-1373-b -n kube-system

gardenctl target -t ev-1373-b -n kube-system
gardenctl target -p everest -n kube-system
gardenctl target -s gcp-eu2 -n kube-system

gardenctl target namespace kube-system

and verified target status in
cat /Users/i352986/.garden/sessions/plantingSession/target
Release note:

Namespace is now supported as one kind of target
gardenctl drop namespace is now supported
gardenctl ls namespaces is now supported

@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 16, 2020
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 16, 2020
@DockToFuture
Copy link
Contributor

Gardenctl drop is currently removing the ns from the stack but not from the kube-config.
And when I'm targeting another shoot i get the kubeconfig printed of the new shoot but I'm still targeting the same shoot.
E.g. target stack is:

target:
- kind: garden
  name: dev
- kind: project
  name: core
- kind: shoot
  name: cli-gcp
- kind: namespace
  name: kube-system

after targeting a new shoot I still have the same shoot in the target stack

$ g target shoot ts-test
Shoot:
KUBECONFIG=/Users/xxx/.garden/cache/dev/projects/core/ts-test/kubeconfig.yaml
xxx at vvv in ~/go/src/github.com/gardener/gardenctl on pr-173
$ g get target
target:
- kind: garden
  name: dev
- kind: project
  name: core
- kind: shoot
  name: cli-gcp
- kind: namespace
  name: kube-system

@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 16, 2020
@neo-liang-sap
Copy link
Contributor Author

Hi @DockToFuture ,

I fixed second issue in c86ab58 , targetShoot miss logic when current target.Target size is 4 (including namespace information)

For the first issue Gardenctl drop is currently removing the ns from the stack but not from the kube-config. sorry i didn't quite get the point, currently as namespace doesn't have kubeconfig information so i put the logic in b6a0bb0#diff-d0d3bde7a059e586e30272e957484afdR633 to b6a0bb0#diff-d0d3bde7a059e586e30272e957484afdR648 and this function getKubeConfigOfCurrentTarget is called in drop() function.

Could you please raise an example for this issue? then i can get an better understandinfg on this...

Thanks a lot!
-Neo

@DockToFuture
Copy link
Contributor

I would expect in the following example, that after I have dropped the namespace from the target stack and I execute g k get pods that I get the pods in the default ns listed. Therefore gardenctl drop has to unset the namespace. WDYT?

$ g get target
target:
- kind: garden
  name: dev
- kind: project
  name: core
- kind: shoot
  name: cli-gcp
- kind: namespace
  name: kube-system
xxx at yyy in ~/go/src/github.com/gardener/gardenctl on pr-173
$ g drop
Dropped namespace kube-system
xxx at yyy in ~/go/src/github.com/gardener/gardenctl on pr-173
$ g get target
target:
- kind: garden
  name: dev
- kind: project
  name: core
- kind: shoot
  name: cli-gcp
xxx at yyy in ~/go/src/github.com/gardener/gardenctl on pr-173
$ g k get pods
NAME                                                             READY   STATUS    RESTARTS   AGE
addons-nginx-ingress-controller-5796c65bf8-cchc7                 1/1     Running   0          2d23h
addons-nginx-ingress-nginx-ingress-k8s-backend-b7c567f7b-nq2lg   1/1     Running   0          2d23h
blackbox-exporter-58cf74dd57-xlq75                               1/1     Running   0          2d23h
calico-kube-controllers-6f864659cf-plw7f                         1/1     Running   0          2d23h
calico-node-hj4wq                                                1/1     Running   0          8h
calico-node-nhj8f                                                1/1     Running   0          8h
calico-typha-deploy-6c5dc7856f-vs2s9                             1/1     Running   0          2d23h
calico-typha-horizontal-autoscaler-6455dc88c9-7fljk              1/1     Running   0          2d23h
calico-typha-vertical-autoscaler-7b9954b9df-962xs                1/1     Running   0          2d23h
coredns-db5c59c87-76pnc                                          1/1     Running   0          2d23h
coredns-db5c59c87-v92jw                                          1/1     Running   0          2d23h
kube-proxy-hhnxm                                                 1/1     Running   0          8h
kube-proxy-zptfc                                                 1/1     Running   0          8h
metrics-server-5d5788576f-t96fw                                  1/1     Running   0          2d23h
node-exporter-8wfqs                                              1/1     Running   0          8h
node-exporter-qwhqh                                              1/1     Running   0          8h
node-problem-detector-kpt7m                                      1/1     Running   0          8h
node-problem-detector-t2p2f                                      1/1     Running   0          8h
vpn-shoot-7fbc9c65b8-t8qt7                                       1/1     Running   0          2d23h

@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 16, 2020
@neo-liang-sap
Copy link
Contributor Author

neo-liang-sap commented Mar 16, 2020

Hi @DockToFuture ,
Thanks for the comments!
I added some logic in drop.go -

  • setting namespace to default while dropping an namespace
  • add logic for dealing with gardenctl drop project/seed while namespace in current target
  • add support for gardenctl drop namespace

also add some code in ls.go and ls_test.go to support gardenctl ls namespaces

Thanks
-Neo

@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 16, 2020
@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 16, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 16, 2020
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 16, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Mar 19, 2020
ReadTarget(pathTarget, &targetReal)

if len(targetReal.Target) == 1 && targetReal.Stack()[0].Kind == "namespace" {
panic("the target has only namespace, this is invalid, at least one garden needs to be targeted before using namespace")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you replace panic function with return errors.New("error message")? User will be confused by the stack trace.

} else if len(targetReal.Target) == 1 && targetReal.Stack()[0].Kind != "namespace" {
target.Target = targetReal.Target
} else {
panic("length of target.Stack is illegal")
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

ReadTarget(pathTarget, &target)

if len(target.Target) > 4 {
panic("the length is greater than 4 and illegal")
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

panic("the length is greater than 4 and illegal")
}
if len(target.Target) == 0 {
panic("the length is 0 and illegal. at least one garden needs to be targeted")
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

}
if len(target.Target) == 1 {
if string(target.Target[0].Kind) != "garden" {
panic("if one element in target, this needs to be garden")
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2020
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Mar 19, 2020
@neo-liang-sap
Copy link
Contributor Author

Hi @DockToFuture ,
thanks, for three occurence of panic i used return errors.New("") to replace.
For two occurence which function doesn't return error but only kubeconfigpath , i use fmt.Println("") to print error message and os.Exit(2) to fail the process

Thanks!

Copy link
Contributor

@DockToFuture DockToFuture left a comment

Choose a reason for hiding this comment

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

/lgtm, thank you for the pr!

@DockToFuture DockToFuture merged commit 5ace9d2 into gardener-attic:master Mar 19, 2020
@neo-liang-sap
Copy link
Contributor Author

thanks @DockToFuture !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants