-
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
4
commits 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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bc205e3
Refactor sampleexternalplugin to be a valid reference implementation
nerdeveloper aafb6f9
Fix PROJECT config unmarshaling and ServiceMonitor template formatting
nerdeveloper d70c339
✨ Enhance sample external plugin: add Prometheus ServiceMonitor and k…
nerdeveloper 5395def
chore: remove outdated README content for testplugin, leaving directo…
nerdeveloper 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
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
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 |
---|---|---|
|
@@ -37,12 +37,8 @@ func flagsCmd(pr *external.PluginRequest) external.PluginResponse { | |
} | ||
|
||
switch pr.Command { | ||
case "init": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about we keep the init and edit? |
||
pluginResponse.Flags = scaffolds.InitFlags | ||
case "create api": | ||
pluginResponse.Flags = scaffolds.ApiFlags | ||
case "create webhook": | ||
pluginResponse.Flags = scaffolds.WebhookFlags | ||
case "edit": | ||
pluginResponse.Flags = scaffolds.EditFlags | ||
default: | ||
pluginResponse.Error = true | ||
pluginResponse.ErrorMsgs = []string{ | ||
|
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
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: | ||
- monitor.yaml | ||
` | ||
|
||
// DefaultKustomizationPatch represents a patch to config/default/kustomization.yaml | ||
type DefaultKustomizationPatch struct { | ||
Path string | ||
Content string | ||
} | ||
|
||
// NewDefaultKustomizationPatch creates a patch comment for the default kustomization.yaml | ||
func NewDefaultKustomizationPatch() *DefaultKustomizationPatch { | ||
return &DefaultKustomizationPatch{ | ||
Path: "config/default/kustomization_prometheus_patch.yaml", | ||
Content: defaultKustomizationPatchTemplate, | ||
} | ||
} | ||
|
||
const defaultKustomizationPatchTemplate = `# [PROMETHEUS] To enable prometheus monitor, uncomment the following line in config/default/kustomization.yaml: | ||
# | ||
# In the resources section, add: | ||
# - ../prometheus | ||
# | ||
# This will include the Prometheus ServiceMonitor 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 | ||
` |
103 changes: 103 additions & 0 deletions
103
...orial/testdata/sampleexternalplugin/v1/internal/test/plugins/prometheus/servicemonitor.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,103 @@ | ||
/* | ||
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 | ||
|
||
import "fmt" | ||
|
||
// ServiceMonitor represents a Prometheus ServiceMonitor manifest | ||
type ServiceMonitor struct { | ||
Path string | ||
Content string | ||
} | ||
|
||
// ServiceMonitorOptions allows configuration of the ServiceMonitor | ||
type ServiceMonitorOptions func(*ServiceMonitor) | ||
|
||
// WithDomain sets the domain for the ServiceMonitor | ||
func WithDomain(domain string) ServiceMonitorOptions { | ||
return func(sm *ServiceMonitor) { | ||
sm.Content = fmt.Sprintf(serviceMonitorTemplate, domain, domain) | ||
} | ||
} | ||
|
||
// WithProjectName sets the project name for the ServiceMonitor | ||
func WithProjectName(projectName string) ServiceMonitorOptions { | ||
return func(sm *ServiceMonitor) { | ||
// Project name can be used for labels or naming | ||
// For now, we'll use it in a future iteration if needed | ||
} | ||
} | ||
|
||
// NewServiceMonitor creates a new ServiceMonitor manifest | ||
func NewServiceMonitor(opts ...ServiceMonitorOptions) *ServiceMonitor { | ||
sm := &ServiceMonitor{ | ||
Path: "config/prometheus/monitor.yaml", | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(sm) | ||
} | ||
|
||
// Set default content if not set by options | ||
if sm.Content == "" { | ||
sm.Content = fmt.Sprintf(serviceMonitorTemplate, "example.com", "example.com") | ||
} | ||
|
||
return sm | ||
} | ||
|
||
const serviceMonitorTemplate = `# Prometheus Monitor Service (Metrics) | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
control-plane: controller-manager | ||
app.kubernetes.io/name: %s | ||
app.kubernetes.io/managed-by: kustomize | ||
name: controller-manager-metrics-service | ||
namespace: system | ||
spec: | ||
ports: | ||
- name: https | ||
port: 8443 | ||
protocol: TCP | ||
targetPort: 8443 | ||
selector: | ||
control-plane: controller-manager | ||
|
||
--- | ||
# Prometheus ServiceMonitor | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
labels: | ||
control-plane: controller-manager | ||
app.kubernetes.io/name: %s | ||
app.kubernetes.io/managed-by: kustomize | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- path: /metrics | ||
port: https | ||
scheme: https | ||
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token | ||
tlsConfig: | ||
insecureSkipVerify: true | ||
selector: | ||
matchLabels: | ||
control-plane: controller-manager | ||
` |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I liked the idea, but it is added in all scaffolds by default.
Could we try to add a file that does not exist by default?
Maybe a Prometheus Config such as: