-
Notifications
You must be signed in to change notification settings - Fork 20
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
Enh/domain targeting #43
Conversation
ShootDomain string `yaml:"shootDomain"` | ||
DashboardDomain string `yaml:"dashboardDomain"` |
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.
Why don't we add a generic Patter Matching mechanism which also can handle technicalID. Add an Array of e.g shootRegexps
or shootMatchPatterns
. The implementation should be generic and could look like https://play.golang.org/p/q7JwrHDu283. I see the code of this more in the config package and not in the target package.
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.
Yes, this sounds like a good Idea. We should document this well, so that users know how to configure their gardens. Would you add this per garden or global? If we have separate regexps per garden, we could keep the functionality of also targeting across multiple gardens with shoot / dashboard urls. Maybe we can have both?
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.
We should document this well, so that users know how to configure their gardens
our goal should be that the user does not have to configure this and it should rather be fetched from somewhere, as we already discussed.
Would you add this per garden or global?
Per garden
If we have separate regexps per garden, we could keep the functionality of also targeting across multiple gardens with shoot / dashboard urls. Maybe we can have both?
I didn't get that
@@ -205,6 +207,14 @@ func (m *managerImpl) resolveProjectName(ctx context.Context, gardenClient clien | |||
return project, err | |||
} | |||
|
|||
func (m *managerImpl) resolveProjectNamespace(ctx context.Context, gardenClient client.Client, projectNamespace string) (*corev1.Namespace, error) { |
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.
The wrapping of garden client function to make them more convenient is something we use in many locations. I think we overload the target manager if add all this convenient methods to him. I would propose to have a separate object/interface e.g GardenerClient.
@@ -282,8 +292,122 @@ func (m *managerImpl) validateSeed(ctx context.Context, seed *gardencorev1beta1. | |||
return nil | |||
} | |||
|
|||
func domainsFromConfiguration(m *managerImpl) (map[string]string, map[string]string, error) { |
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.
Why is this a method on the manger. It doe not use the manger.
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.
probably this happened during refactoring. I will fix this.
return "", "" | ||
} | ||
|
||
func targetFlagsFromDomain(ctx context.Context, m *managerImpl, t *targetImpl, name string) (TargetFlags, error) { |
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.
This should be a method of the managerImp. It should return a Target and not a TargetFlags. Why does it have in input parameter of type targteImpl. There is no need to depend on an impl of an interface. The only info we use is the gardenName.
return nil, nil | ||
} | ||
|
||
func isDomainFormat(name string) bool { |
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.
Why not strings.Contains
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.
Yes you are right, I started with a more complex regex but simplified it more and more to support all cases and ended with contains-a-dot.
I ask myself if it is a good idea if we pass this kind of identifiers to target shoot. This breaks shoot completions is is from my point of view something completely different because it rewrites the traget completely on not only the shoot. |
I asked myself the same question. My first approach was to introduce a new target kind something like Overall I feel that there are lots of things to discuss here |
@@ -10,7 +10,6 @@ import ( | |||
"context" | |||
"errors" | |||
"fmt" | |||
|
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.
revert
Did a tool that you used do this? Maybe it's misconfigured as we should be grouping imports by std, project and external
ShootDomain string `yaml:"shootDomain"` | ||
DashboardDomain string `yaml:"dashboardDomain"` |
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.
We should document this well, so that users know how to configure their gardens
our goal should be that the user does not have to configure this and it should rather be fetched from somewhere, as we already discussed.
Would you add this per garden or global?
Per garden
If we have separate regexps per garden, we could keep the functionality of also targeting across multiple gardens with shoot / dashboard urls. Maybe we can have both?
I didn't get that
err := gardenClient.Get(ctx, key, namespace) | ||
|
||
return namespace, err |
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.
err := gardenClient.Get(ctx, key, namespace)
return namespace, err
I have never seen such a pattern before, usually this is done:
if err := gardenClient.Get(ctx, key, namespace); err != nil {
return nil, err
}
return namespace, nil
} | ||
|
||
if len(dashboardDomains) == 0 && len(shootDomains) == 0 { | ||
return nil, fmt.Errorf("no domain found in configured gardens. Shoot targeting via domain requires shoot and / or dashboard domain configuration for each garden that you want to enable domain targeting for") |
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 need to format your error message use fmt.Errorf()
, if you don't use errors.New()
.
-> in this case, use errors.New()
if namespace == nil { | ||
return nil, fmt.Errorf("invalid namespace in shoot url") | ||
} |
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.
I don't think this can ever happen
|
||
match := domainRegexp.FindStringSubmatch(domain) | ||
if match != nil { | ||
return NewTargetFlags(garden, match[2], "", match[1]), nil |
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.
I think it makes it hard to read what match[2] and match[1] really means, it probably makes more sense to extract it to a variable and name it appropriately
if targetFlags != nil { | ||
t.Garden = targetFlags.GardenName() | ||
t.Project = targetFlags.ProjectName() | ||
t.Shoot = targetFlags.ShootName() | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("failed to target shoot with url: %s", shootName) |
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.
Nit: I'd prefer to turn it around
if targetFlags != nil { | |
t.Garden = targetFlags.GardenName() | |
t.Project = targetFlags.ProjectName() | |
t.Shoot = targetFlags.ShootName() | |
return nil | |
} | |
return fmt.Errorf("failed to target shoot with url: %s", shootName) | |
if targetFlags == nil { | |
return fmt.Errorf("failed to target shoot with url: %s", shootName) | |
} | |
t.Garden = targetFlags.GardenName() | |
t.Project = targetFlags.ProjectName() | |
t.Shoot = targetFlags.ShootName() | |
return nil |
maybe change this PR to draft as also the tests are missing? |
closed in favor for #44 |
What this PR does / why we need it:
This PR introduces basic domain targeting.
Shoots can be targeted via dashboard url or shoot api server url.
To enable domain targeting, you have to extend your garden configuration:
Which issue(s) this PR fixes:
Fixes #38
Special notes for your reviewer:
Release note: