-
Notifications
You must be signed in to change notification settings - Fork 1.6k
π Refactor sampleexternalplugin to be a Valid Reference Implementation #5116
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -71,6 +71,17 @@ structures. | |||
| } | ||||
| ``` | ||||
|
|
||||
| **Example `PluginRequest` (triggered by `kubebuilder edit --plugins sampleexternalplugin/v1 --namespace monitoring`):** | ||||
|
|
||||
| ```json | ||||
| { | ||||
| "apiVersion": "v1alpha1", | ||||
| "args": ["--namespace", "monitoring"], | ||||
| "command": "edit", | ||||
| "universe": {} | ||||
| } | ||||
| ``` | ||||
|
|
||||
| ### PluginResponse | ||||
|
|
||||
| `PluginResponse` contains the modifications made by the plugin to the project. This data is serialized as JSON and returned to Kubebuilder through `stdout`. | ||||
|
|
@@ -79,13 +90,15 @@ structures. | |||
| ```json | ||||
| { | ||||
| "apiVersion": "v1alpha1", | ||||
| "command": "init", | ||||
| "command": "edit", | ||||
| "metadata": { | ||||
| "description": "The `init` subcommand initializes a project via Kubebuilder. It scaffolds a single file: `initFile`.", | ||||
| "examples": "kubebuilder init --plugins sampleexternalplugin/v1 --domain my.domain" | ||||
| "description": "The `edit` subcommand adds Prometheus instance configuration for monitoring your operator.", | ||||
| "examples": "kubebuilder edit --plugins sampleexternalplugin/v1 --namespace monitoring" | ||||
| }, | ||||
| "universe": { | ||||
| "initFile": "A file created with the `init` subcommand." | ||||
| "config/prometheus/prometheus.yaml": "# Prometheus instance manifest with RBAC...", | ||||
| "config/prometheus/kustomization.yaml": "resources:\n - prometheus.yaml\n", | ||||
|
||||
| "config/prometheus/kustomization.yaml": "resources:\n - prometheus.yaml\n", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Binaries for programs and plugins | ||
| *.exe | ||
| *.exe~ | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
| sampleexternalplugin | ||
| bin/ | ||
|
|
||
| # Test binary, built with `go test -c` | ||
| *.test | ||
|
|
||
| # Output of the go coverage tool, specifically when used with LiteIDE | ||
| *.out | ||
|
|
||
| # Go workspace file | ||
| go.work | ||
|
|
||
| # Temporary test directories | ||
| testdata/testplugin/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,7 @@ func metadataCmd(pr *external.PluginRequest) external.PluginResponse { | |
| // Here is an example of parsing multiple flags from a Kubebuilder external plugin request | ||
| flagsToParse := pflag.NewFlagSet("flagsFlags", pflag.ContinueOnError) | ||
| flagsToParse.Bool("init", false, "sets the init flag to true") | ||
| flagsToParse.Bool("api", false, "sets the api flag to true") | ||
| flagsToParse.Bool("webhook", false, "sets the webhook flag to true") | ||
| flagsToParse.Bool("edit", false, "sets the edit flag to true") | ||
|
|
||
| if err := flagsToParse.Parse(pr.Args); err != nil { | ||
| pluginResponse.Error = true | ||
|
|
@@ -52,21 +51,18 @@ func metadataCmd(pr *external.PluginRequest) external.PluginResponse { | |
| } | ||
|
|
||
| initFlag, _ := flagsToParse.GetBool("init") | ||
| apiFlag, _ := flagsToParse.GetBool("api") | ||
| webhookFlag, _ := flagsToParse.GetBool("webhook") | ||
| editFlag, _ := flagsToParse.GetBool("edit") | ||
|
|
||
| // The Phase 2 Plugins implementation will only ever pass a single boolean flag | ||
| // argument in the JSON request `args` field. The flag will be `--init` if it is | ||
| // attempting to get the flags for the `init` subcommand, `--api` for `create api`, | ||
| // `--webhook` for `create webhook`, and `--edit` for `edit` | ||
| // argument in the JSON request `args` field. | ||
| if initFlag { | ||
| // Populate the JSON response `metadata` field with a description | ||
| // and examples for the `init` subcommand | ||
| pluginResponse.Metadata = scaffolds.InitMeta | ||
| } else if apiFlag { | ||
| pluginResponse.Metadata = scaffolds.ApiMeta | ||
| } else if webhookFlag { | ||
| pluginResponse.Metadata = scaffolds.WebhookMeta | ||
| } else if editFlag { | ||
| // Populate the JSON response `metadata` field with a description | ||
| // and examples for the `edit` subcommand | ||
| pluginResponse.Metadata = scaffolds.EditMeta | ||
| } else { | ||
| pluginResponse.Error = true | ||
| pluginResponse.ErrorMsgs = []string{ | ||
|
Comment on lines
66
to
68
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,22 @@ | ||
| module v1 | ||
|
|
||
| go 1.24.5 | ||
| go 1.25.0 | ||
|
|
||
| require ( | ||
| github.com/spf13/afero v1.15.0 | ||
| github.com/spf13/pflag v1.0.10 | ||
| sigs.k8s.io/kubebuilder/v4 v4.9.0 | ||
| ) | ||
|
|
||
| replace sigs.k8s.io/kubebuilder/v4 => ../../../../../../../ | ||
|
|
||
| require ( | ||
| github.com/gobuffalo/flect v1.0.3 // indirect | ||
| github.com/spf13/afero v1.15.0 // indirect | ||
| golang.org/x/mod v0.28.0 // indirect | ||
| github.com/kr/pretty v0.3.1 // indirect | ||
| go.yaml.in/yaml/v2 v2.4.2 // indirect | ||
| golang.org/x/mod v0.29.0 // indirect | ||
| golang.org/x/sync v0.17.0 // indirect | ||
| golang.org/x/text v0.29.0 // indirect | ||
| golang.org/x/tools v0.37.0 // indirect | ||
| golang.org/x/text v0.30.0 // indirect | ||
| golang.org/x/tools v0.38.0 // indirect | ||
| sigs.k8s.io/yaml v1.6.0 // indirect | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| Copyright 2022 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| package prometheus | ||
|
|
||
| // DefaultKustomizationPatch represents instructions for adding Prometheus to the default kustomization.yaml | ||
| type DefaultKustomizationPatch struct { | ||
| Path string | ||
| Content string | ||
| } | ||
|
|
||
| // NewDefaultKustomizationPatch creates instructions for adding Prometheus to config/default/kustomization.yaml | ||
| func NewDefaultKustomizationPatch() *DefaultKustomizationPatch { | ||
| return &DefaultKustomizationPatch{ | ||
| Path: "config/default/kustomization_prometheus_patch.yaml", | ||
| Content: defaultKustomizationPatchTemplate, | ||
| } | ||
| } | ||
|
|
||
| const defaultKustomizationPatchTemplate = `# [PROMETHEUS] To enable prometheus monitoring, add the following to config/default/kustomization.yaml: | ||
| # | ||
| # In the resources section, add: | ||
| # - ../prometheus/prometheus.yaml | ||
| # | ||
| # This will include the Prometheus instance in your deployment. | ||
| # Make sure you have the Prometheus Operator installed in your cluster. | ||
| # | ||
| # For more information, see: https://github.com/prometheus-operator/prometheus-operator | ||
nerdeveloper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ` | ||
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.
What does it means namespace
monitoring?Why this flag would be required?