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

Refactor operator package installation #1542

Merged
merged 5 commits into from
Jun 4, 2020
Merged

Conversation

nfnt
Copy link
Member

@nfnt nfnt commented May 29, 2020

What this PR does / why we need it:
The old InstallPackage function has been extracted into a separate package. It's functionality has been split up into multiple functions handling different installation resources. The function signature of install.Package introduces variadic option parameters to provide a backward-compatible API.

In preparation for #1514

@nfnt nfnt self-assigned this May 29, 2020
The old 'InstallPackage' function has been extracted into a separate package. It's functionality has been split up into multiple functions handling different installation resources. The function signature of 'install.Package' introduces variadic option parameters to provide a backwards-compatible API.

Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt nfnt force-pushed the nfnt/refactor-package-install branch from aaa183d to de69d7f Compare June 2, 2020 06:38
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

Nice work! I left a few comments/nits around package structure and logging.

pkg/kudoctl/packages/install/install.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/install/install.go Outdated Show resolved Hide resolved
return nil
}

if err := validateParameters(
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we validate parameters before we jump out in L83

Copy link
Member Author

Choose a reason for hiding this comment

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

Parameter validation is only important for instances, that's why it's only done when actually installing an instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

In case of KEP-29, we're allowing potentially broken parameters to skip the validation and make it to the server

Copy link
Member Author

Choose a reason for hiding this comment

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

The old code skipped this validation if no instance was to be installed. I moved it to run as early as possible now with the reasons you mentioned.

}
}

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Much cleaner 👏

pkg/kudoctl/packages/install/install.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/install/install.go Outdated Show resolved Hide resolved
pkg/kudoctl/packages/install/install.go Outdated Show resolved Hide resolved
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
)

type Options struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to adopt the type.go-pattern as with other packages and keep all general types in an install/types.go. It keeps entangling cyclic dependencies later much easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding a install.types.go won't change anything regarding cyclic dependencies, because it would still be in the same package. For this it would need to be in types.go of the packages package. I consider this an anti-pattern, types should be declared close to the functions using this type. Cyclic dependencies can be resolved by good package management following SRP.

Copy link
Contributor

@zen-dog zen-dog Jun 2, 2020

Choose a reason for hiding this comment

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

Adding a install.types.go won't change anything regarding cyclic dependencies

not yet, that's why I wrote that it becomes easier "later" 😉 I would only welcome it if you move other files into their own sub-packages.

I consider this an anti-pattern

well, k8s codebase disagrees with you, and frankly so do I. we adopted this pattern for a good reason. Lack of fine-grained imports in Go makes it challenging to avoid cyclic dependencies.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have yet to see where the Kubernetes code base disagrees. Their usage of types.go is done to provide consistency when using generators like deepcopy-gen or other kubebuilder tools on structures that are supposed to be used as part of the Kubernetes API. Which isn't the case here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The can be multiple reasons for that. And again, being forced to resolve multiple cyclic dependencies (and giving up on at least one of them) in our codebase makes me appreciate this pattern a lot. Especially in a package like install which is potentially used by server and client and itself uses server types (like Instance). But I guess we'll have to agree to disagree here.

pkg/kudoctl/packages/install/operator.go Outdated Show resolved Hide resolved
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
)

func installOperatorAndOperatorVersion(client *kudo.Client, resources packages.Resources) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, we'll need this method for the dependencies.

* Easier option handling
* Improved logging

Signed-off-by: Jan Schlicht <jan@d2iq.com>
Jan Schlicht added 2 commits June 3, 2020 14:55
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Signed-off-by: Jan Schlicht <jan@d2iq.com>
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

Nice work!

Signed-off-by: Jan Schlicht <jan@d2iq.com>
@nfnt nfnt merged commit 2464231 into master Jun 4, 2020
@nfnt nfnt deleted the nfnt/refactor-package-install branch June 4, 2020 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants