Skip to content

Commit

Permalink
include group name in crd patches and rbac editor/viewer files
Browse files Browse the repository at this point in the history
  • Loading branch information
rmb938 committed Jan 30, 2022
1 parent e395f98 commit 334da7c
Show file tree
Hide file tree
Showing 125 changed files with 2,059 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type EnableCAInjectionPatch struct {
// SetTemplateDefaults implements file.Template
func (f *EnableCAInjectionPatch) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[plural].yaml")
f.Path = filepath.Join("config", "crd", "patches", "cainjection_in_%[group]_%[plural].yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type EnableWebhookPatch struct {
// SetTemplateDefaults implements file.Template
func (f *EnableWebhookPatch) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[plural].yaml")
f.Path = filepath.Join("config", "crd", "patches", "webhook_in_%[group]_%[plural].yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CRDEditorRole struct {
// SetTemplateDefaults implements file.Template
func (f *CRDEditorRole) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "%[kind]_editor_role.yaml")
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_editor_role.yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CRDViewerRole struct {
// SetTemplateDefaults implements file.Template
func (f *CRDViewerRole) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "%[kind]_viewer_role.yaml")
f.Path = filepath.Join("config", "rbac", "%[group]_%[kind]_viewer_role.yaml")
}
f.Path = f.Resource.Replacer().Replace(f.Path)

Expand Down
5 changes: 4 additions & 1 deletion test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ function scaffold_test_project {

$kb create api --group apps --version v1 --kind Deployment --controller=true --resource=false --make=false

$kb create api --group foo --version v1 --kind Bar --controller=true --resource=true --make=false
$kb create api --group fiz --version v1 --kind Bar --controller=true --resource=true --make=false

if [ $project == "project-v3-multigroup" ]; then
$kb create api --version v1 --kind Lakers --controller=true --resource=true --make=false
$kb create webhook --version v1 --kind Lakers --defaulting --programmatic-validation
Expand Down Expand Up @@ -127,4 +130,4 @@ scaffold_test_project project-v3
scaffold_test_project project-v3-multigroup
scaffold_test_project project-v3-addon --plugins="go/v3,declarative"
scaffold_test_project project-v3-config --component-config
scaffold_test_project project-v3-v1beta1
scaffold_test_project project-v3-v1beta1
6 changes: 6 additions & 0 deletions testdata/project-v2-multigroup/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ resources:
- group: foo.policy
kind: HealthCheckPolicy
version: v1
- group: foo
kind: Bar
version: v1
- group: fiz
kind: Bar
version: v1
version: "2"
64 changes: 64 additions & 0 deletions testdata/project-v2-multigroup/apis/fiz/v1/bar_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// BarSpec defines the desired state of Bar
type BarSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Bar. Edit bar_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// BarStatus defines the observed state of Bar
type BarStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Bar is the Schema for the bars API
type Bar struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BarSpec `json:"spec,omitempty"`
Status BarStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BarList contains a list of Bar
type BarList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bar `json:"items"`
}

func init() {
SchemeBuilder.Register(&Bar{}, &BarList{})
}
36 changes: 36 additions & 0 deletions testdata/project-v2-multigroup/apis/fiz/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 v1 contains API Schema definitions for the fiz v1 API group
//+kubebuilder:object:generate=true
//+groupName=fiz.testproject.org
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "fiz.testproject.org", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
115 changes: 115 additions & 0 deletions testdata/project-v2-multigroup/apis/fiz/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions testdata/project-v2-multigroup/apis/foo/v1/bar_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
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 v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// BarSpec defines the desired state of Bar
type BarSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Bar. Edit bar_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// BarStatus defines the observed state of Bar
type BarStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Bar is the Schema for the bars API
type Bar struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BarSpec `json:"spec,omitempty"`
Status BarStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// BarList contains a list of Bar
type BarList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Bar `json:"items"`
}

func init() {
SchemeBuilder.Register(&Bar{}, &BarList{})
}
36 changes: 36 additions & 0 deletions testdata/project-v2-multigroup/apis/foo/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 v1 contains API Schema definitions for the foo v1 API group
//+kubebuilder:object:generate=true
//+groupName=foo.testproject.org
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "foo.testproject.org", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Loading

0 comments on commit 334da7c

Please sign in to comment.