-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 : add kustomize file for crd sample #3084
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:master
from
Kavinjsir:feat/kustomize-sample
Nov 23, 2022
Merged
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
There are no files selected for viewing
This file contains 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 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 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
70 changes: 70 additions & 0 deletions
70
...ns/common/kustomize/v2-alpha/scaffolds/internal/templates/config/samples/kustomization.go
This file contains 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,70 @@ | ||
/* | ||
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 samples | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"path/filepath" | ||
"text/template" | ||
|
||
"sigs.k8s.io/kubebuilder/v3/pkg/machinery" | ||
) | ||
|
||
var _ machinery.Template = &Kustomization{} | ||
|
||
// Kustomization scaffolds a file that defines the kustomization scheme for the prometheus folder | ||
type Kustomization struct { | ||
machinery.TemplateMixin | ||
|
||
CRDManifests []string | ||
} | ||
|
||
// SetTemplateDefaults implements file.Template | ||
func (f *Kustomization) SetTemplateDefaults() error { | ||
if f.Path == "" { | ||
f.Path = filepath.Join("config", "samples", "kustomization.yaml") | ||
} | ||
|
||
defaultTemplate, err := f.createTemplate() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.TemplateBody = defaultTemplate | ||
|
||
f.IfExistsAction = machinery.OverwriteFile | ||
|
||
return nil | ||
} | ||
|
||
func (f *Kustomization) createTemplate() (string, error) { | ||
t := template.Must(template.New("customResourcesConfig").Parse(kustomizationTemplate)) | ||
|
||
outputTmpl := &bytes.Buffer{} | ||
if err := t.Execute(outputTmpl, f.CRDManifests); err != nil { | ||
return "", fmt.Errorf("error when generating sample kustomization manifest: %w", err) | ||
} | ||
|
||
return outputTmpl.String(), nil | ||
|
||
} | ||
|
||
const kustomizationTemplate = `--- | ||
resources:{{ range $i ,$e := . }} | ||
- {{ . }}{{end}} | ||
` |
This file contains 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,5 @@ | ||
--- | ||
resources: | ||
- crew_v1_captain.yaml | ||
- crew_v1_firstmate.yaml | ||
- crew_v1_admiral.yaml |
5 changes: 5 additions & 0 deletions
5
testdata/project-v4-declarative-v1/config/samples/kustomization.yaml
This file contains 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,5 @@ | ||
--- | ||
resources: | ||
- crew_v1_captain.yaml | ||
- crew_v1_firstmate.yaml | ||
- crew_v1_admiral.yaml |
13 changes: 13 additions & 0 deletions
13
testdata/project-v4-multigroup/config/samples/kustomization.yaml
This file contains 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,13 @@ | ||
--- | ||
resources: | ||
- crew_v1_captain.yaml | ||
- ship_v1beta1_frigate.yaml | ||
- ship_v1_destroyer.yaml | ||
- ship_v2alpha1_cruiser.yaml | ||
- sea-creatures_v1beta1_kraken.yaml | ||
- sea-creatures_v1beta2_leviathan.yaml | ||
- foo.policy_v1_healthcheckpolicy.yaml | ||
- apps_v1_deployment.yaml | ||
- foo_v1_bar.yaml | ||
- fiz_v1_bar.yaml | ||
- _v1_lakers.yaml |
This file contains 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,5 @@ | ||
--- | ||
resources: | ||
- crew_v1_captain.yaml | ||
- crew_v1_firstmate.yaml | ||
- crew_v1_admiral.yaml |
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.
Hi @Kavinjsir great work, just a few nits:
a) We cannot use 🌱 on this one because this change affects the end-user so that need to be
sparkles
b) We need also add this to the migration guide from v3 to v4
However, all is great. Just address this both needs it has my lgtm
c/c @everettraven @varshaprasad96 this one helps SDK because their has a plugin manifests that will create this file so that is possible build the bundle with the owned CRDs
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.
Hi @camilamacedo86 thx for reminding the documentation. Just added some in the place you suggested.