-
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
Open
nerdeveloper
wants to merge
1
commit into
kubernetes-sigs:master
Choose a base branch
from
nerdeveloper:refactor-sampleexternalplugin-issue-4824
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+399
β484
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...torial/testdata/sampleexternalplugin/v1/internal/test/plugins/prometheus/kustomization.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| 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 | ||
|
|
||
| // PrometheusKustomization represents the kustomization.yaml for Prometheus resources | ||
| type PrometheusKustomization struct { | ||
| Path string | ||
| Content string | ||
| } | ||
|
|
||
| // NewPrometheusKustomization creates a new kustomization.yaml for Prometheus resources | ||
| func NewPrometheusKustomization() *PrometheusKustomization { | ||
| return &PrometheusKustomization{ | ||
| Path: "config/prometheus/kustomization.yaml", | ||
| Content: prometheusKustomizationTemplate, | ||
| } | ||
| } | ||
|
|
||
| const prometheusKustomizationTemplate = `resources: | ||
| - prometheus.yaml | ||
| ` | ||
|
|
||
| // 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
|
||
| ` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The documentation example shows
config/prometheus/kustomization.yamlbeing created in the universe (line 100), but the actual implementation doesn't scaffold this file. This inconsistency between documentation and implementation could mislead users. Either update the documentation to match the actual files created or modify the plugin to scaffold this file.