-
Notifications
You must be signed in to change notification settings - Fork 42
add restriction support like eu-access restriction #245
add restriction support like eu-access restriction #245
Conversation
/cc @petersutter |
2319d05
to
11cebfa
Compare
11cebfa
to
5452952
Compare
@gardener/gardenctl-maintainers any comments on this PR? |
per communication with @petersutter , he will review this PR after back from holiday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm, however to improve the readability of the code I have made some suggestions
config := reader.ReadConfig(pathGardenConfig) | ||
for _, garden := range config.GardenClusters { | ||
if garden.Name == gardenName && len(garden.AccessRestrictions) > 0 { | ||
ars = garden.AccessRestrictions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have a match you can return already here or at least break the loop
pkg/cmd/target.go
Outdated
@@ -1011,6 +1068,11 @@ func shootWrapper(targetReader TargetReader, targetWriter TargetWriter, configRe | |||
return fmt.Errorf("no match for %q", args[1]) | |||
} else if len(shoots) == 1 { | |||
targetShoot(targetWriter, shoots[0]) | |||
warningMsg := checkShootsRestriction(shoots[0], configReader, target.Stack()[0].Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract target.Stack()[0].Name
to variable for better readability
pkg/cmd/target.go
Outdated
for j := 0; j < len(ars); j++ { | ||
ar := ars[j] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use range loop if you do not need the index
pkg/cmd/target.go
Outdated
for i := 0; i < len(ar.Options); i++ { | ||
option := ar.Options[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, use range loop
pkg/cmd/target.go
Outdated
if _, ok := shootMatchLabels[ar.Key]; ok { | ||
if shootMatchLabels[ar.Key] == strconv.FormatBool(ar.NotifyIf) { | ||
warningMsg += ar.Msg | ||
warningMsg += "\n" | ||
//if upper level msg will not show, neither will lower level msg show | ||
if len(ar.Options) > 0 { | ||
for i := 0; i < len(ar.Options); i++ { | ||
option := ar.Options[i] | ||
if _, ok := shootAnnotations[option.Key]; ok { | ||
if shootAnnotations[option.Key] == strconv.FormatBool(option.NotifyIf) { | ||
warningMsg += option.Msg | ||
warningMsg += "\n" | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to simplify nested if statements, use early return pattern. This improves readability
5452952
to
a2367d2
Compare
Hello @petersutter , i've fixed my PR per your comments, thanks for your review! -Neo |
|
I was using the command wrong for targeting a shoot by missing the bash-5.0$ ./gardenctl-darwin-amd64 target deleteme
Shoot:
KUBECONFIG=/Users/d050337/.garden/cache/dev-virtual/projects/core/deleteme/kubeconfig.yaml
bash-5.0$ ./gardenctl-darwin-amd64 target shoot deleteme
Shoot:
KUBECONFIG=/Users/d050337/.garden/cache/dev-virtual/projects/core/deleteme/kubeconfig.yaml
Attention, EU-Access is enabled!
Do not debug cluster addons! |
Interesting. I will check the code and update here. Thanks! |
a2367d2
to
756ebfb
Compare
Hi @petersutter , thanks for your catch! yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
What this PR does / why we need it:
This PR will display eu-access restriction warning msg in gardenctl terminal if cluster is configed with eu-access and garden config is configed with enabling the eu-access
Which issue(s) this PR fixes:
Fixes #232
Special notes for your reviewer:
To use this PR:
shoot:
a. config eu-access
b. config node-eu-access
c. addons eu-access
garden config:
a. has/has no access restriction
b. true/false in access restriction key and option key
Release note: