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

Enh/domain targeting #43

Closed
wants to merge 3 commits into from
Closed

Enh/domain targeting #43

wants to merge 3 commits into from

Conversation

grolu
Copy link
Contributor

@grolu grolu commented Oct 8, 2021

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:

gardens:
  - name: foo-garden
    kubeconfig: ~/.kube/foo-kubeconfig
    shootDomain: shoot.gardener.cloud #shoot API sever domain
    dashboardDomain: dashboard.gardener.cloud #url to gardener dashboard

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

Special notes for your reviewer:

Release note:

@grolu grolu requested a review from a team as a code owner October 8, 2021 14:18
@gardener-robot gardener-robot added needs/review Needs review size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Oct 8, 2021
@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) 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 Oct 8, 2021
Comment on lines +24 to +25
ShootDomain string `yaml:"shootDomain"`
DashboardDomain string `yaml:"dashboardDomain"`
Copy link
Member

@holgerkoser holgerkoser Oct 11, 2021

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.

Copy link
Contributor Author

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?

Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

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

Why not strings.Contains

Copy link
Contributor Author

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.

@holgerkoser
Copy link
Member

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.

@grolu
Copy link
Contributor Author

grolu commented Oct 11, 2021

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 gardenctl target domain <shootdomain>, however I abandoned this attempt when I had another look at gardener-attic/gardenctl#499 where the domain targeting example does not have a dedicated target kind but uses target shoot <shootdomain> after thinking about it I decided that this makes sense as also with the current targeting it may happen that you change multiple values of your target (e.g. dropping seed and setting project).

Overall I feel that there are lots of things to discuss here

@@ -10,7 +10,6 @@ import (
"context"
"errors"
"fmt"

Copy link
Member

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

Comment on lines +24 to +25
ShootDomain string `yaml:"shootDomain"`
DashboardDomain string `yaml:"dashboardDomain"`
Copy link
Member

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

Comment on lines +213 to +215
err := gardenClient.Get(ctx, key, namespace)

return namespace, err
Copy link
Member

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")
Copy link
Member

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()

Comment on lines +358 to +360
if namespace == nil {
return nil, fmt.Errorf("invalid namespace in shoot url")
}
Copy link
Member

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
Copy link
Member

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

Comment on lines +401 to +408
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)
Copy link
Member

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

Suggested change
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

@petersutter
Copy link
Member

maybe change this PR to draft as also the tests are missing?

@grolu
Copy link
Contributor Author

grolu commented Oct 14, 2021

closed in favor for #44

@grolu grolu closed this Oct 14, 2021
@grolu grolu deleted the enh/domain_targeting branch November 7, 2021 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) needs/review Needs review size/m Size of pull request is medium (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Domain Targeting
5 participants