Skip to content

Commit 5b04b5e

Browse files
committed
📖 Refactor sampleexternalplugin to be a valid reference implementation
Transform the sample external plugin from mock scaffolding to a realistic Prometheus monitoring generator that demonstrates best practices for external plugin development. Key changes: - Implement init and edit subcommands that scaffold Prometheus instance manifests - Add PROJECT config reading to align with internal plugin patterns - Replace mock ServiceMonitor with complete Prometheus CR including RBAC - Add --namespace flag support to demonstrate argument passing - Update documentation with realistic examples showing argument usage - Fix error handling to properly validate PROJECT file existence - Centralize kustomization in config/default/kustomization.yaml (no separate prometheus kustomization) - Provide clear instructions for users to add Prometheus resources manually The plugin now serves as a proper reference implementation for: - Reading PROJECT configuration in external plugins - Scaffolding production-ready Kubernetes manifests - Supporting command-line arguments (--namespace flag) - Testing plugins against local Kubebuilder source - Adding optional monitoring features via edit subcommand - Following Kubebuilder's centralized kustomization pattern Addresses maintainer feedback on PR kubernetes-sigs#5116 including proper error handling, argument passing examples, realistic manifest generation, and centralized kustomization. Fixes kubernetes-sigs#4824
1 parent 4c2adc8 commit 5b04b5e

File tree

21 files changed

+470
-502
lines changed

21 files changed

+470
-502
lines changed

docs/book/src/plugins/extending/external-plugins.md

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ structures.
7171
}
7272
```
7373

74+
**Example `PluginRequest` (triggered by `kubebuilder edit --plugins sampleexternalplugin/v1 --namespace monitoring`):**
75+
76+
```json
77+
{
78+
"apiVersion": "v1alpha1",
79+
"args": ["--namespace", "monitoring"],
80+
"command": "edit",
81+
"universe": {}
82+
}
83+
```
84+
7485
### PluginResponse
7586

7687
`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.
7990
```json
8091
{
8192
"apiVersion": "v1alpha1",
82-
"command": "init",
93+
"command": "edit",
8394
"metadata": {
84-
"description": "The `init` subcommand initializes a project via Kubebuilder. It scaffolds a single file: `initFile`.",
85-
"examples": "kubebuilder init --plugins sampleexternalplugin/v1 --domain my.domain"
95+
"description": "The `edit` subcommand adds Prometheus instance configuration for monitoring your operator.",
96+
"examples": "kubebuilder edit --plugins sampleexternalplugin/v1 --namespace monitoring"
8697
},
8798
"universe": {
88-
"initFile": "A file created with the `init` subcommand."
99+
"config/prometheus/prometheus.yaml": "# Prometheus instance manifest with RBAC...",
100+
"config/prometheus/kustomization.yaml": "resources:\n - prometheus.yaml\n",
101+
"config/default/kustomization_prometheus_patch.yaml": "# Patch to enable Prometheus in default kustomization..."
89102
},
90103
"error": false,
91104
"errorMsgs": []
@@ -150,26 +163,20 @@ Otherwise, Kubebuilder would search for the plugins in a default path based on y
150163
You can now use it by calling the CLI commands:
151164

152165
```sh
153-
# Initialize a new project with the external plugin named `sampleplugin`
154-
kubebuilder init --plugins sampleplugin/v1
155-
156-
# Display help information of the `init` subcommand of the external plugin
157-
kubebuilder init --plugins sampleplugin/v1 --help
158-
159-
# Create a new API with the above external plugin with a customized flag `number`
160-
kubebuilder create api --plugins sampleplugin/v1 --number 2
166+
# Initialize a new project with Prometheus monitoring
167+
kubebuilder init --plugins sampleexternalplugin/v1
161168

162-
# Create a webhook with the above external plugin with a customized flag `hooked`
163-
kubebuilder create webhook --plugins sampleplugin/v1 --hooked
169+
# Update an existing project with Prometheus monitoring
170+
kubebuilder edit --plugins sampleexternalplugin/v1
164171

165-
# Update the project configuration with the above external plugin
166-
kubebuilder edit --plugins sampleplugin/v1
172+
# Display help information for the init subcommand
173+
kubebuilder init --plugins sampleexternalplugin/v1 --help
167174

168-
# Create new APIs with external plugins v1 and v2 by respecting the plugin chaining order
169-
kubebuilder create api --plugins sampleplugin/v1,sampleplugin/v2
175+
# Display help information for the edit subcommand
176+
kubebuilder edit --plugins sampleexternalplugin/v1 --help
170177

171-
# Create new APIs with the go/v4 plugin and then pass those files to the external plugin by respecting the plugin chaining order
172-
kubebuilder create api --plugins go/v4,sampleplugin/v1
178+
# Plugin chaining example: Use go/v4 plugin first, then apply external plugin
179+
kubebuilder edit --plugins go/v4,sampleexternalplugin/v1
173180
```
174181

175182
## Further resources
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
sampleexternalplugin
8+
bin/
9+
10+
# Test binary, built with `go test -c`
11+
*.test
12+
13+
# Output of the go coverage tool, specifically when used with LiteIDE
14+
*.out
15+
16+
# Go workspace file
17+
go.work
18+
19+
# Temporary test directories
20+
testdata/testplugin/

docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ install: build ## Build and install the binary with the current source code. Use
6363
.PHONY: test-plugin
6464
test-plugin: ## Run the plugin test.
6565
./test/test.sh
66+
67+
.PHONY: clean
68+
clean: ## Clean build artifacts.
69+
rm -rf ./bin

docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/cmd/cmd.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,13 @@ func Run() {
5959

6060
// Run logic depending on the command that is requested by Kubebuilder
6161
switch pluginRequest.Command {
62-
// the `init` subcommand is often used when initializing a new project
62+
// the `init` subcommand is used to add features during project initialization
6363
case "init":
6464
response = scaffolds.InitCmd(pluginRequest)
65-
// the `create api` subcommand is often used after initializing a project
66-
// with the `init` subcommand to create a controller and CRDs for a
67-
// provided group, version, and kind
68-
case "create api":
69-
response = scaffolds.ApiCmd(pluginRequest)
70-
// the `create webhook` subcommand is often used after initializing a project
71-
// with the `init` subcommand to create a webhook for a provided
72-
// group, version, and kind
73-
case "create webhook":
74-
response = scaffolds.WebhookCmd(pluginRequest)
65+
// the `edit` subcommand is used to add optional features to an existing project
66+
// This is a realistic use case for external plugins - adding optional monitoring
67+
case "edit":
68+
response = scaffolds.EditCmd(pluginRequest)
7569
// the `flags` subcommand is used to customize the flags that
7670
// the Kubebuilder cli will bind for use with this plugin
7771
case "flags":

docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/cmd/flags.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package cmd
1717

1818
import (
19+
"fmt"
1920
"v1/scaffolds"
2021

2122
"sigs.k8s.io/kubebuilder/v4/pkg/plugin/external"
@@ -36,17 +37,27 @@ func flagsCmd(pr *external.PluginRequest) external.PluginResponse {
3637
Flags: []external.Flag{},
3738
}
3839

39-
switch pr.Command {
40+
// Parse args to determine which subcommand flags are being requested
41+
var subcommand string
42+
for _, arg := range pr.Args {
43+
if arg == "--init" {
44+
subcommand = "init"
45+
break
46+
} else if arg == "--edit" {
47+
subcommand = "edit"
48+
break
49+
}
50+
}
51+
52+
switch subcommand {
4053
case "init":
4154
pluginResponse.Flags = scaffolds.InitFlags
42-
case "create api":
43-
pluginResponse.Flags = scaffolds.ApiFlags
44-
case "create webhook":
45-
pluginResponse.Flags = scaffolds.WebhookFlags
55+
case "edit":
56+
pluginResponse.Flags = scaffolds.EditFlags
4657
default:
4758
pluginResponse.Error = true
4859
pluginResponse.ErrorMsgs = []string{
49-
"unrecognized command: " + pr.Command,
60+
fmt.Sprintf("unrecognized subcommand flag in args (received %d args)", len(pr.Args)),
5061
}
5162
}
5263

docs/book/src/simple-external-plugin-tutorial/testdata/sampleexternalplugin/v1/cmd/metadata.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func metadataCmd(pr *external.PluginRequest) external.PluginResponse {
4040
// Here is an example of parsing multiple flags from a Kubebuilder external plugin request
4141
flagsToParse := pflag.NewFlagSet("flagsFlags", pflag.ContinueOnError)
4242
flagsToParse.Bool("init", false, "sets the init flag to true")
43-
flagsToParse.Bool("api", false, "sets the api flag to true")
44-
flagsToParse.Bool("webhook", false, "sets the webhook flag to true")
43+
flagsToParse.Bool("edit", false, "sets the edit flag to true")
4544

4645
if err := flagsToParse.Parse(pr.Args); err != nil {
4746
pluginResponse.Error = true
@@ -52,21 +51,18 @@ func metadataCmd(pr *external.PluginRequest) external.PluginResponse {
5251
}
5352

5453
initFlag, _ := flagsToParse.GetBool("init")
55-
apiFlag, _ := flagsToParse.GetBool("api")
56-
webhookFlag, _ := flagsToParse.GetBool("webhook")
54+
editFlag, _ := flagsToParse.GetBool("edit")
5755

5856
// The Phase 2 Plugins implementation will only ever pass a single boolean flag
59-
// argument in the JSON request `args` field. The flag will be `--init` if it is
60-
// attempting to get the flags for the `init` subcommand, `--api` for `create api`,
61-
// `--webhook` for `create webhook`, and `--edit` for `edit`
57+
// argument in the JSON request `args` field.
6258
if initFlag {
6359
// Populate the JSON response `metadata` field with a description
6460
// and examples for the `init` subcommand
6561
pluginResponse.Metadata = scaffolds.InitMeta
66-
} else if apiFlag {
67-
pluginResponse.Metadata = scaffolds.ApiMeta
68-
} else if webhookFlag {
69-
pluginResponse.Metadata = scaffolds.WebhookMeta
62+
} else if editFlag {
63+
// Populate the JSON response `metadata` field with a description
64+
// and examples for the `edit` subcommand
65+
pluginResponse.Metadata = scaffolds.EditMeta
7066
} else {
7167
pluginResponse.Error = true
7268
pluginResponse.ErrorMsgs = []string{
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
module v1
22

3-
go 1.24.5
3+
go 1.25.0
44

55
require (
6+
github.com/spf13/afero v1.15.0
67
github.com/spf13/pflag v1.0.10
78
sigs.k8s.io/kubebuilder/v4 v4.9.0
89
)
910

11+
replace sigs.k8s.io/kubebuilder/v4 => ../../../../../../../
12+
1013
require (
1114
github.com/gobuffalo/flect v1.0.3 // indirect
12-
github.com/spf13/afero v1.15.0 // indirect
13-
golang.org/x/mod v0.28.0 // indirect
15+
github.com/kr/pretty v0.3.1 // indirect
16+
go.yaml.in/yaml/v2 v2.4.2 // indirect
17+
golang.org/x/mod v0.29.0 // indirect
1418
golang.org/x/sync v0.17.0 // indirect
15-
golang.org/x/text v0.29.0 // indirect
16-
golang.org/x/tools v0.37.0 // indirect
19+
golang.org/x/text v0.30.0 // indirect
20+
golang.org/x/tools v0.38.0 // indirect
21+
sigs.k8s.io/yaml v1.6.0 // indirect
1722
)
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
22
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
3+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
34
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
45
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
56
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -13,12 +14,20 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1314
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1415
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 h1:EEHtgt9IwisQ2AZ4pIsMjahcegHh6rmhqxzIRQIyepY=
1516
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6/go.mod h1:I6V7YzU0XDpsHqbsyrghnFZLO1gwK6NPTNvmetQIk9U=
16-
github.com/onsi/ginkgo/v2 v2.25.3 h1:Ty8+Yi/ayDAGtk4XxmmfUy4GabvM+MegeB4cDLRi6nw=
17-
github.com/onsi/ginkgo/v2 v2.25.3/go.mod h1:43uiyQC4Ed2tkOzLsEYm7hnrb7UJTWHYNsuy3bG/snE=
17+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
18+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
19+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
20+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
21+
github.com/onsi/ginkgo/v2 v2.27.2 h1:LzwLj0b89qtIy6SSASkzlNvX6WktqurSHwkk2ipF/Ns=
22+
github.com/onsi/ginkgo/v2 v2.27.2/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo=
1823
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
1924
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
25+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
2026
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2127
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
28+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
29+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
30+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
2231
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
2332
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
2433
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
@@ -30,29 +39,27 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
3039
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
3140
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
3241
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
33-
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
34-
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
3542
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
3643
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
3744
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
3845
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
39-
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
40-
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
41-
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
42-
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
46+
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
47+
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
48+
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
49+
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
4350
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
4451
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
45-
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
46-
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
47-
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
48-
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
49-
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
50-
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
52+
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
53+
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
54+
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
55+
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
56+
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
57+
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
5158
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
59+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
60+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
5261
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5362
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5463
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
55-
sigs.k8s.io/kubebuilder/v4 v4.9.0 h1:9e9LnQy/wQ24IZDIqye6iZZFOB9aKNyNfjnfsy3S8cw=
56-
sigs.k8s.io/kubebuilder/v4 v4.9.0/go.mod h1:Xql7wLeyXBQ4lJJdi1Pl8T/DeV4UXpA1kaOEumN0pzY=
5764
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
5865
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package prometheus
17+
18+
// DefaultKustomizationPatch represents instructions for adding Prometheus to the default kustomization.yaml
19+
type DefaultKustomizationPatch struct {
20+
Path string
21+
Content string
22+
}
23+
24+
// NewDefaultKustomizationPatch creates instructions for adding Prometheus to config/default/kustomization.yaml
25+
func NewDefaultKustomizationPatch() *DefaultKustomizationPatch {
26+
return &DefaultKustomizationPatch{
27+
Path: "config/default/kustomization_prometheus_patch.yaml",
28+
Content: defaultKustomizationPatchTemplate,
29+
}
30+
}
31+
32+
const defaultKustomizationPatchTemplate = `# [PROMETHEUS] To enable prometheus monitoring, add the following to config/default/kustomization.yaml:
33+
#
34+
# In the resources section, add:
35+
# - ../prometheus/prometheus.yaml
36+
#
37+
# This will include the Prometheus instance in your deployment.
38+
# Make sure you have the Prometheus Operator installed in your cluster.
39+
#
40+
# For more information, see: https://github.com/prometheus-operator/prometheus-operator
41+
`

0 commit comments

Comments
 (0)