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

feat(plugins): deny plugin creation #843

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gciezkowski-acc
Copy link
Contributor

@gciezkowski-acc gciezkowski-acc commented Jan 14, 2025

Description

Deny the creation of plugin by the user. When plugin has annotation greenhouse.sap/allow-create you can create the plugin.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help
  • Separate ticket for tests # (issue/pr)

You can run the test using command:
make clean-e2e && make cli && make setup-webhook && make setup-e2e && make e2e-local SCENARIO=plugin

Added to documentation?

  • 📜 README.md
  • 🤝 Documentation pages updated
  • 🙅 no documentation needed
  • (if applicable) generated OpenAPI docs for CRD changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

@gciezkowski-acc gciezkowski-acc changed the title Feat/829 deny plugin creation feat(plugins) deny plugin creation Jan 14, 2025
@gciezkowski-acc gciezkowski-acc changed the title feat(plugins) deny plugin creation feat(plugins): deny plugin creation Jan 14, 2025
@gciezkowski-acc gciezkowski-acc force-pushed the feat/829_deny_plugin_creation branch 2 times, most recently from 02a1e9a to ef77e22 Compare January 14, 2025 12:29
@gciezkowski-acc gciezkowski-acc force-pushed the feat/829_deny_plugin_creation branch from ef77e22 to 79334e6 Compare January 14, 2025 12:43
@gciezkowski-acc gciezkowski-acc marked this pull request as ready for review January 14, 2025 12:57
@gciezkowski-acc gciezkowski-acc requested a review from a team as a code owner January 14, 2025 12:57
@uwe-mayer uwe-mayer linked an issue Jan 24, 2025 that may be closed by this pull request
2 tasks
Copy link
Contributor

@uwe-mayer uwe-mayer left a comment

Choose a reason for hiding this comment

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

Thanks for this.

It came to mind, and this might be a blocker:

Currently we can only deploy Plugins to the central cluster (no clusterName in Plugin.Spec).
Shipping this would deny creating any Plugin on the central cluster, as there is no way to reference it in a Preset...

cc @IvoGoman

@@ -90,16 +104,26 @@ var _ = Describe("Plugin E2E", Ordered, func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(pluginDefinitionList.Items)).To(BeEquivalentTo(1))

By("Creating the plugin")
By("Try to creating the plugin")
Copy link
Contributor

@uwe-mayer uwe-mayer Jan 24, 2025

Choose a reason for hiding this comment

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

Suggested change
By("Try to creating the plugin")
By("Trying to create the plugin")

@@ -80,6 +80,8 @@ const (
HelmUninstallFailedReason ConditionReason = "HelmUninstallFailed"
)

const AllowCreateAnnotation = "greenhouse.sap/allow-create"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should live in well_known.go

and be reused from there...

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also add go docs for the Annotation

@@ -144,6 +149,12 @@ func ValidateDeletePlugin(_ context.Context, _ client.Client, _ runtime.Object)
return nil, nil
}

func allowCreatePlugin(plugin *greenhousev1alpha1.Plugin) bool {
_, ok := plugin.Annotations["greenhouse.sap/allow-create"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not use strings. Reuse from well_known.go. See comment in plugin_types.go

@@ -80,6 +80,8 @@ const (
HelmUninstallFailedReason ConditionReason = "HelmUninstallFailed"
)

const AllowCreateAnnotation = "greenhouse.sap/allow-create"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const AllowCreateAnnotation = "greenhouse.sap/allow-create"
const AllowPluginCreateAnnotation = "greenhouse.sap/allow-plugin-create"

Copy link
Contributor

Choose a reason for hiding this comment

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

Please move to well_known.go :)

test.WithReleaseNamespace(env.TestNamespace),
test.WithPluginOptionValue("replicaCount", &apiextensionsv1.JSON{Raw: []byte("1")}, nil))
err = adminClient.Create(ctx, testPlugin)
Expect(err).To(HaveOccurred())
Copy link
Contributor

@uwe-mayer uwe-mayer Jan 24, 2025

Choose a reason for hiding this comment

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

Let's not go the PluginPreset way here. Let's annotate the test plugin with AllowPluginCreateAnnotation and test from there. So the Plugin creation path can test the resources are created on the remote and the PluginPreset creation path tests the subsequent Plugins are created according to the clusterSelector

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add the step of trying to apply the Plugin without annotation first. And expecting it to fail.

if testPluginPreset.Annotations == nil {
testPluginPreset.Annotations = map[string]string{}
}
delete(testPluginPreset.Annotations, "greenhouse.sap/prevent-deletion")
Copy link
Contributor

Choose a reason for hiding this comment

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

Obsolete if we only test the Plugin without preset, but:

No strings please. This should also live in well_known.go

Or was it a deliberate decision to not expose this annotation publicly @IvoGoman ?

@@ -279,7 +302,11 @@ var _ = Describe("Validate plugin spec fields", Ordered, func() {

It("should reject to update a plugin when the pluginDefinition changes", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect a test
"It should deny creation of a Plugin without AllowPluginCreationAnnotation"

Resources: []string{"plugins", "pluginpresets"},
Resources: []string{"pluginpresets"},
},
// Grant read, update and delete permissions for PluginPresets to organization plugin admins. No create
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Grant read, update and delete permissions for PluginPresets to organization plugin admins. No create
// Grant read, update and delete permissions for Plugins to organization plugin admins. No create

@@ -208,6 +208,21 @@ func SetOptionValueForPlugin(plugin *greenhousev1alpha1.Plugin, key, value strin
})
}

// SetOptionValueForPluginPreset sets the value of a PluginOtionValue
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// SetOptionValueForPluginPreset sets the value of a PluginOtionValue
// SetOptionValueForPluginPreset sets the value of a PluginOptionValue

Copy link
Contributor

Choose a reason for hiding this comment

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

I like it, but it seems unused in our current code base?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] - Deny creation of Plugins
2 participants