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

Add defaultIncludePrereleases #4165

Merged
merged 9 commits into from
Jan 31, 2022

Conversation

antgamdia
Copy link
Contributor

Description of the change

Having considered #4085 (comment), the purpose of this PR is twofold:

  1. Add a defaultIncludePrereleases param in the plugin-specific config to decide whether or not we should add the VersionSelectionSemverPrereleases{} when creating the installed pkg.
  2. Refactor a little bit the way the plugin config is created (mainly creating a type) and improve the tests.
    1. We weren't checking the actual InstalledPackage being created in a test case, so this PR also includes some minor changes in the test case

Benefits

Until we have a way to configure some options from the UI, this PR introduces a way to configure some plugin-specific options, specifically defaultIncludePrereleases for allowing installing pre-releases by kapp-controller.

Possible drawbacks

N/A

Applicable issues

Additional information

N/A

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
Comment on lines +3532 to +3538
createdPkgInstall, err := s.getPkgInstall(context.Background(), "default", tc.request.TargetContext.Namespace, createInstalledPackageResponse.InstalledPackageRef.Identifier)
if err != nil {
t.Fatalf("%+v", err)
}

if got, want := createdPkgInstall, tc.expectedPackageInstall; !cmp.Equal(want, got, ignoreUnexported) {
t.Errorf("mismatch (-want +got):\n%s", cmp.Diff(want, got, ignoreUnexported))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing assert added in this PR

PackageRef: &packagingv1alpha1.PackageRef{
RefName: "tetris.foo.example.com",
VersionSelection: &vendirversions.VersionSelectionSemver{
Constraints: ">=1.0.0 <1.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test cases for the constraints when passing a defaultUpgradePolicy

@@ -2885,110 +2891,58 @@ func TestCreateInstalledPackage(t *testing.T) {
PackageRef: &packagingv1alpha1.PackageRef{
RefName: "tetris.foo.example.com",
VersionSelection: &vendirversions.VersionSelectionSemver{
Constraints: "1.2.3",
Constraints: "1.0.0",
Prereleases: &vendirversions.VersionSelectionSemverPrereleases{},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test case enabling the defaultIncludePrereleases

Comment on lines 2615 to 2632
Key: "values.yaml",
},
},
},
Paused: false,
Canceled: false,
SyncPeriod: &metav1.Duration{(time.Second * 30)},
SyncPeriod: nil,
NoopDelete: false,
},
Status: packagingv1alpha1.PackageInstallStatus{
GenericStatus: kappctrlv1alpha1.GenericStatus{
ObservedGeneration: 1,
Conditions: []kappctrlv1alpha1.AppCondition{{
Type: kappctrlv1alpha1.ReconcileSucceeded,
Status: k8scorev1.ConditionTrue,
Reason: "baz",
Message: "qux",
}},
FriendlyDescription: "foo",
UsefulErrorMessage: "Deployed",
ObservedGeneration: 0,
Conditions: nil,
FriendlyDescription: "",
UsefulErrorMessage: "",
},
Version: "1.2.3",
LastAttemptedVersion: "1.2.3",
Version: "",
LastAttemptedVersion: "",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minor changes in the test cases to match the actual PackageInstall being created.

Comment on lines 332 to 334
kappControllerPluginParsedConfig struct {
defaultUpgradePolicy upgradePolicy
defaultIncludePrereleases bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Struct holding the plugin's config.


// parse the configuration options
defaultUpgradePolicy := upgradePolicyMapping[pluginConfig.KappController.Packages.V1alpha1.DefaultUpgradePolicy]
defaultIncludePrereleases, err := strconv.ParseBool(pluginConfig.KappController.Packages.V1alpha1.DefaultUpgradePolicy)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is pluginConfig.KappController.Packages.V1alpha1.DefaultUpgradePolicy the right param to parse for defaultIncludePrereleases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely right! I didn't notice, thanks!

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
@@ -1638,6 +1638,8 @@ kubeappsapis:
## @param kubeappsapis.pluginConfig.kappController.packages.v1alpha1.defaultUpgradePolicy Default upgrade policy generating version constraints
## enum: [ "major", "minor", "patch", "none" ]
defaultUpgradePolicy: none
## @param kubeappsapis.pluginConfig.kappController.packages.v1alpha1.defaultIncludePrereleases Default policy for allowing pre-releases to be installed
defaultIncludePrereleases: false
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, just a thought: I know I'd suggested a boolean when reviewing your other PR - but it might be just as simple to actually have a value here (ie. rename defaultPrereleasesVersionSelection that is empty (nil) by default, but can be set to {} or whatever? This way, we don't have to later change this config option to support actually setting version selections for pre releases? I'm not suggesting we implement support for them yet, it'd still effectively be a boolean option for now, but one that doesn't need to change later.

Fine either way.

Copy link
Contributor Author

@antgamdia antgamdia Jan 28, 2022

Choose a reason for hiding this comment

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

No, it's fine. In fact, after re-reading the carvel issues and docs I've started having some doubts/questions, so I asked them at: https://kubernetes.slack.com/archives/CH8KCCKA5/p1643376802571959

In short, prereleases can have three values:

  1. prereleases: {}: allow any prerelease if the version constraint allows it.
  2. prereleases: nil: disallow any prerelease
    • Exception: if the version constraint is a prerelease itself:
      1. Current behavior: error, it won't install a prerelease if prereleases: nil:
      2. Future behavior: install it, it won't be required to set prereleases: {} if the version constraint is a prerelease
  3. prereleases: {Identifiers: []string{"rc"}}: allow only prerelease with "rc" as part of the name if the version constraint allows it.

I'm not suggesting we implement support for them yet, it'd still effectively be a boolean option for now, but one that doesn't need to change later.

It is mostly the same effort, I mean, it is just a matter of appending strings or not. I'll update this PR with the full implementation soon (edit: done). Thanks for the suggestion, much better this way!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I'd like to add (in a separate PR) another default config like allowDowngrading or sth, to add the packaging.carvel.dev/downgradable: " annotation to the PackageInstall objs to allow them to be downgraded: https://carvel.dev/kapp-controller/docs/latest/package-consumer-concepts/#downgrading

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, yes, that'd be useful (as a kubeapps config default).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: #4192 :)

Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>

Conflicts:
	cmd/kubeapps-apis/plugins/kapp_controller/packages/v1alpha1/server_data_adapters.go
	cmd/kubeapps-apis/plugins/kapp_controller/packages/v1alpha1/server_test.go
Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>

Conflicts:
	cmd/kubeapps-apis/plugins/kapp_controller/packages/v1alpha1/server.go
	cmd/kubeapps-apis/plugins/kapp_controller/packages/v1alpha1/server_test.go
@antgamdia antgamdia merged commit d765c48 into vmware-tanzu:main Jan 31, 2022
@antgamdia antgamdia deleted the addDefaultIncludePrereleases branch January 31, 2022 15:42
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

3 participants