Skip to content

Commit

Permalink
✨ cleanup stale label in v2 scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Mengqi Yu committed Jun 6, 2019
1 parent 1d0e96b commit a80870c
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 114 deletions.
4 changes: 2 additions & 2 deletions pkg/scaffold/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (p *V1Project) Scaffold() error {
&scaffoldv1.KustomizeImagePatch{},
&metricsauthv1.KustomizePrometheusMetricsPatch{},
&metricsauthv1.KustomizeAuthProxyPatch{},
&project.AuthProxyService{},
&scaffoldv1.AuthProxyService{},
&project.AuthProxyRole{},
&project.AuthProxyRoleBinding{},
&manager.Config{Image: imgName},
Expand Down Expand Up @@ -184,7 +184,7 @@ func (p *V2Project) Scaffold() error {
&scaffoldv2.KustomizeImagePatch{},
&metricsauthv2.KustomizePrometheusMetricsPatch{},
&metricsauthv2.KustomizeAuthProxyPatch{},
&project.AuthProxyService{},
&scaffoldv2.AuthProxyService{},
&project.AuthProxyRole{},
&project.AuthProxyRoleBinding{},
&managerv2.Config{Image: imgName},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package project
package v1

import (
"path/filepath"
Expand All @@ -24,7 +24,7 @@ import (

var _ input.File = &AuthProxyService{}

// AuthProxyService scaffolds the config/rbac/auth_proxy_role.yaml file
// AuthProxyService scaffolds the config/rbac/auth_proxy_service.yaml file
type AuthProxyService struct {
input.Input
}
Expand Down
65 changes: 0 additions & 65 deletions pkg/scaffold/v1/resource/rolebinding.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,46 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package resource
package v2

import (
"fmt"
"path/filepath"

"sigs.k8s.io/kubebuilder/pkg/scaffold/input"
)

var _ input.File = &Role{}
var _ input.File = &AuthProxyService{}

// Role scaffolds the config/manager/group_role_rbac.yaml file
type Role struct {
// AuthProxyService scaffolds the config/rbac/auth_proxy_service.yaml file
type AuthProxyService struct {
input.Input

// Resource is a resource in the API group
Resource *Resource
}

// GetInput implements input.File
func (r *Role) GetInput() (input.Input, error) {
func (r *AuthProxyService) GetInput() (input.Input, error) {
if r.Path == "" {
r.Path = filepath.Join("config", "manager", fmt.Sprintf(
"%s_role_rbac.yaml", r.Resource.Group))
r.Path = filepath.Join("config", "rbac", "auth_proxy_service.yaml")
}
r.TemplateBody = roleTemplate
r.TemplateBody = AuthProxyServiceTemplate
return r.Input, nil
}

// Validate validates the values
func (r *Role) Validate() error {
return r.Resource.Validate()
}

var roleTemplate = `apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
var AuthProxyServiceTemplate = `apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/port: "8443"
prometheus.io/scheme: https
prometheus.io/scrape: "true"
labels:
controller-tools.k8s.io: "1.0"
name: {{.Resource.Group}}-role
rules:
- apiGroups:
- {{ .Resource.Group }}.{{ .Domain }}
resources:
- '*'
verbs:
- '*'
control-plane: controller-manager
name: controller-manager-metrics-service
namespace: system
spec:
ports:
- name: https
port: 8443
targetPort: https
selector:
control-plane: controller-manager
`
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/crd/enablecainjection_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v2
package crd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/crd/enablewebhook_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v2
package crd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/crd/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v2
package crd

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/crd/kustomizeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package v2
package crd

import (
"path/filepath"
Expand Down
4 changes: 0 additions & 4 deletions pkg/scaffold/v2/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ kind: Namespace
metadata:
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
name: system
---
apiVersion: apps/v1
Expand All @@ -55,18 +54,15 @@ metadata:
namespace: system
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
spec:
selector:
matchLabels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
replicas: 1
template:
metadata:
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
spec:
containers:
- command:
Expand Down
1 change: 0 additions & 1 deletion pkg/scaffold/v2/webhook/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ spec:
targetPort: 443
selector:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
`
4 changes: 0 additions & 4 deletions testdata/project-v2/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: Namespace
metadata:
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
name: system
---
apiVersion: apps/v1
Expand All @@ -13,18 +12,15 @@ metadata:
namespace: system
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
spec:
selector:
matchLabels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
replicas: 1
template:
metadata:
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
spec:
containers:
- command:
Expand Down
2 changes: 0 additions & 2 deletions testdata/project-v2/config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ metadata:
prometheus.io/scrape: "true"
labels:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
name: controller-manager-metrics-service
namespace: system
spec:
Expand All @@ -17,4 +16,3 @@ spec:
targetPort: https
selector:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"
1 change: 0 additions & 1 deletion testdata/project-v2/config/webhook/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ spec:
targetPort: 443
selector:
control-plane: controller-manager
controller-tools.k8s.io: "1.0"

0 comments on commit a80870c

Please sign in to comment.