Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1190 from justinsb/dont_rewrite_shared_vars
Avoid rewriting template values, mark them as const
  • Loading branch information
k8s-ci-robot committed Nov 14, 2019
2 parents 28fb4c5 + 7b632b2 commit 0742025
Show file tree
Hide file tree
Showing 70 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion pkg/scaffold/project/authproxyrole.go
Expand Up @@ -38,7 +38,7 @@ func (r *AuthProxyRole) GetInput() (input.Input, error) {
return r.Input, nil
}

var proxyRoleTemplate = `apiVersion: rbac.authorization.k8s.io/v1
const proxyRoleTemplate = `apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: proxy-role
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/project/authproxyrolebinding.go
Expand Up @@ -38,7 +38,7 @@ func (r *AuthProxyRoleBinding) GetInput() (input.Input, error) {
return r.Input, nil
}

var proxyRoleBindinggTemplate = `apiVersion: rbac.authorization.k8s.io/v1
const proxyRoleBindinggTemplate = `apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: proxy-rolebinding
Expand Down
4 changes: 2 additions & 2 deletions pkg/scaffold/project/boilerplate.go
Expand Up @@ -65,7 +65,7 @@ func (c *Boilerplate) GetInput() (input.Input, error) {
return c.Input, nil
}

var apache = `/*
const apache = `/*
{{ if .Owner }}Copyright {{ .Year }} {{ .Owner }}.
{{ end }}
Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -81,6 +81,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/`

var none = `/*
const none = `/*
{{ if .Owner }}Copyright {{ .Year }} {{ .Owner }}{{ end }}.
*/`
2 changes: 1 addition & 1 deletion pkg/scaffold/project/gitignore.go
Expand Up @@ -36,7 +36,7 @@ func (c *GitIgnore) GetInput() (input.Input, error) {
return c.Input, nil
}

var gitignoreTemplate = `
const gitignoreTemplate = `
# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/project/gopkg.go
Expand Up @@ -134,7 +134,7 @@ const DefaultGopkgUserContent = `required = [
`

var depTemplate = `{{ .UserContent }}
const depTemplate = `{{ .UserContent }}
# STANZAS BELOW ARE GENERATED AND MAY BE WRITTEN - DO NOT MODIFY BELOW THIS LINE.
{{ range $element := .Stanzas -}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/project/kustomize.go
Expand Up @@ -51,7 +51,7 @@ func (c *Kustomize) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizeTemplate = `# Adds namespace to all resources.
const kustomizeTemplate = `# Adds namespace to all resources.
namespace: {{.Prefix}}-system
# Value of this field is prepended to the
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/project/kustomize_manager_base.go
Expand Up @@ -39,6 +39,6 @@ func (c *KustomizeManager) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizeManagerTemplate = `resources:
const kustomizeManagerTemplate = `resources:
- manager.yaml
`
2 changes: 1 addition & 1 deletion pkg/scaffold/project/kustomize_rbac_base.go
Expand Up @@ -39,7 +39,7 @@ func (c *KustomizeRBAC) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizeRBACTemplate = `resources:
const kustomizeRBACTemplate = `resources:
- rbac_role.yaml
- rbac_role_binding.yaml
# Comment the following 3 lines if you want to disable
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/project/makefile.go
Expand Up @@ -48,7 +48,7 @@ func (c *Makefile) GetInput() (input.Input, error) {
return c.Input, nil
}

var makefileTemplate = `
const makefileTemplate = `
# Image URL to use all building/pushing image targets
IMG ?= {{ .Image }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/authproxyservice.go
Expand Up @@ -38,7 +38,7 @@ func (r *AuthProxyService) GetInput() (input.Input, error) {
return r.Input, nil
}

var AuthProxyServiceTemplate = `apiVersion: v1
const AuthProxyServiceTemplate = `apiVersion: v1
kind: Service
metadata:
annotations:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/controller/add.go
Expand Up @@ -45,7 +45,7 @@ func (a *AddController) GetInput() (input.Input, error) {
return a.Input, nil
}

var addControllerTemplate = `{{ .Boilerplate }}
const addControllerTemplate = `{{ .Boilerplate }}
package controller
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/controller/controller.go
Expand Up @@ -97,7 +97,7 @@ func getResourceInfo(coreGroups map[string]string, r *resource.Resource, in inpu
return path.Join(in.Repo, "pkg", "apis"), r.Group + "." + in.Domain
}

var controllerTemplate = `{{ .Boilerplate }}
const controllerTemplate = `{{ .Boilerplate }}
package {{ lower .Resource.Kind }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/controller/controllersuitetest.go
Expand Up @@ -42,7 +42,7 @@ func (a *SuiteTest) GetInput() (input.Input, error) {
return a.Input, nil
}

var controllerSuiteTestTemplate = `{{ .Boilerplate }}
const controllerSuiteTestTemplate = `{{ .Boilerplate }}
package {{ lower .Resource.Kind }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/controller/controllertest.go
Expand Up @@ -66,7 +66,7 @@ func (a *Test) GetInput() (input.Input, error) {
return a.Input, nil
}

var controllerTestTemplate = `{{ .Boilerplate }}
const controllerTestTemplate = `{{ .Boilerplate }}
package {{ lower .Resource.Kind }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/addtoscheme.go
Expand Up @@ -52,7 +52,7 @@ func (a *AddToScheme) Validate() error {
// NB(directxman12): we need that package alias on the API import otherwise imports.Process
// gets wicked (or hella, if you're feeling west-coasty) confused.

var addResourceTemplate = `{{ .Boilerplate }}
const addResourceTemplate = `{{ .Boilerplate }}
package apis
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/crd_sample.go
Expand Up @@ -52,7 +52,7 @@ func (c *CRDSample) Validate() error {
return c.Resource.Validate()
}

var crdSampleTemplate = `apiVersion: {{ .Resource.Group }}.{{ .Domain }}/{{ .Resource.Version }}
const crdSampleTemplate = `apiVersion: {{ .Resource.Group }}.{{ .Domain }}/{{ .Resource.Version }}
kind: {{ .Resource.Kind }}
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/doc.go
Expand Up @@ -50,7 +50,7 @@ func (a *Doc) Validate() error {
return a.Resource.Validate()
}

var docGoTemplate = `{{ .Boilerplate }}
const docGoTemplate = `{{ .Boilerplate }}
// Package {{.Resource.Version}} contains API Schema definitions for the {{ .Resource.GroupImportSafe }} {{.Resource.Version}} API group
// +k8s:openapi-gen=true
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/group.go
Expand Up @@ -47,7 +47,7 @@ func (g *Group) Validate() error {
return g.Resource.Validate()
}

var groupTemplate = `{{ .Boilerplate }}
const groupTemplate = `{{ .Boilerplate }}
// Package {{ .Resource.GroupImportSafe }} contains {{ .Resource.Group }} API versions
package {{ .Resource.GroupImportSafe }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/register.go
Expand Up @@ -47,7 +47,7 @@ func (r *Register) Validate() error {
return r.Resource.Validate()
}

var registerTemplate = `{{ .Boilerplate }}
const registerTemplate = `{{ .Boilerplate }}
// NOTE: Boilerplate only. Ignore this file.
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/types.go
Expand Up @@ -51,7 +51,7 @@ func (t *Types) Validate() error {
return t.Resource.Validate()
}

var typesTemplate = `{{ .Boilerplate }}
const typesTemplate = `{{ .Boilerplate }}
package {{ .Resource.Version }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/typestest.go
Expand Up @@ -51,7 +51,7 @@ func (t *TypesTest) Validate() error {
return t.Resource.Validate()
}

var typesTestTemplate = `{{ .Boilerplate }}
const typesTestTemplate = `{{ .Boilerplate }}
package {{ .Resource.Version }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/crd/version_suitetest.go
Expand Up @@ -49,7 +49,7 @@ func (v *VersionSuiteTest) Validate() error {
return v.Resource.Validate()
}

var versionSuiteTestTemplate = `{{ .Boilerplate }}
const versionSuiteTestTemplate = `{{ .Boilerplate }}
package {{ .Resource.Version }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/kustomize_image_patch.go
Expand Up @@ -46,7 +46,7 @@ func (c *KustomizeImagePatch) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizeImagePatchTemplate = `apiVersion: apps/v1
const kustomizeImagePatchTemplate = `apiVersion: apps/v1
kind: StatefulSet
metadata:
name: controller-manager
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/apis.go
Expand Up @@ -58,7 +58,7 @@ func (a *APIs) GetInput() (input.Input, error) {
return a.Input, nil
}

var apisTemplate = `{{ .Boilerplate }}
const apisTemplate = `{{ .Boilerplate }}
{{ range $line := .Comments }}{{ $line }}
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/cmd.go
Expand Up @@ -38,7 +38,7 @@ func (a *Cmd) GetInput() (input.Input, error) {
return a.Input, nil
}

var cmdTemplate = `{{ .Boilerplate }}
const cmdTemplate = `{{ .Boilerplate }}
package main
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/config.go
Expand Up @@ -40,7 +40,7 @@ func (c *Config) GetInput() (input.Input, error) {
return c.Input, nil
}

var configTemplate = `apiVersion: v1
const configTemplate = `apiVersion: v1
kind: Namespace
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/controller.go
Expand Up @@ -38,7 +38,7 @@ func (c *Controller) GetInput() (input.Input, error) {
return c.Input, nil
}

var controllerTemplate = `{{ .Boilerplate }}
const controllerTemplate = `{{ .Boilerplate }}
package controller
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/dockerfile.go
Expand Up @@ -36,7 +36,7 @@ func (c *Dockerfile) GetInput() (input.Input, error) {
return c.Input, nil
}

var dockerfileTemplate = `# Build the manager binary
const dockerfileTemplate = `# Build the manager binary
FROM golang:1.10.3 as builder
# Copy in the go src
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/manager/webhook.go
Expand Up @@ -38,7 +38,7 @@ func (c *Webhook) GetInput() (input.Input, error) {
return c.Input, nil
}

var webhookTemplate = `{{ .Boilerplate }}
const webhookTemplate = `{{ .Boilerplate }}
package webhook
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/metricsauth/kustomize_auth_proxy_patch.go
Expand Up @@ -40,7 +40,7 @@ func (c *KustomizeAuthProxyPatch) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the controller manager,
const kustomizeAuthProxyPatchTemplate = `# This patch inject a sidecar container which is a HTTP proxy for the controller manager,
# it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: StatefulSet
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/metricsauth/kustomize_metrics_patch.go
Expand Up @@ -40,7 +40,7 @@ func (c *KustomizePrometheusMetricsPatch) GetInput() (input.Input, error) {
return c.Input, nil
}

var kustomizePrometheusMetricsPatchTemplate = `# This patch enables Prometheus scraping for the manager pod.
const kustomizePrometheusMetricsPatchTemplate = `# This patch enables Prometheus scraping for the manager pod.
apiVersion: apps/v1
kind: StatefulSet
metadata:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/add_admissionbuilder_handler.go
Expand Up @@ -49,7 +49,7 @@ func (a *AddAdmissionWebhookBuilderHandler) GetInput() (input.Input, error) {
return a.Input, nil
}

var addAdmissionWebhookBuilderHandlerTemplate = `{{ .Boilerplate }}
const addAdmissionWebhookBuilderHandlerTemplate = `{{ .Boilerplate }}
package {{ .Server }}server
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/add_server.go
Expand Up @@ -45,7 +45,7 @@ func (a *AddServer) GetInput() (input.Input, error) {
return a.Input, nil
}

var addServerTemplate = `{{ .Boilerplate }}
const addServerTemplate = `{{ .Boilerplate }}
package webhook
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/admissionbuilder.go
Expand Up @@ -75,7 +75,7 @@ func (a *AdmissionWebhookBuilder) GetInput() (input.Input, error) {
return a.Input, nil
}

var admissionWebhookBuilderTemplate = `{{ .Boilerplate }}
const admissionWebhookBuilderTemplate = `{{ .Boilerplate }}
package {{ .Type }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/admissionhandler.go
Expand Up @@ -74,7 +74,7 @@ func (a *AdmissionHandler) GetInput() (input.Input, error) {
return a.Input, nil
}

var addAdmissionHandlerTemplate = `{{ .Boilerplate }}
const addAdmissionHandlerTemplate = `{{ .Boilerplate }}
package {{ .Type }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/admissionwebhooks.go
Expand Up @@ -51,7 +51,7 @@ func (a *AdmissionWebhooks) GetInput() (input.Input, error) {
return a.Input, nil
}

var webhooksTemplate = `{{ .Boilerplate }}
const webhooksTemplate = `{{ .Boilerplate }}
package {{ .Type }}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v1/webhook/server.go
Expand Up @@ -45,7 +45,7 @@ func (a *Server) GetInput() (input.Input, error) {
return a.Input, nil
}

var serverTemplate = `{{ .Boilerplate }}
const serverTemplate = `{{ .Boilerplate }}
package {{ .Server }}server
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/authproxyservice.go
Expand Up @@ -38,7 +38,7 @@ func (r *AuthProxyService) GetInput() (input.Input, error) {
return r.Input, nil
}

var AuthProxyServiceTemplate = `apiVersion: v1
const AuthProxyServiceTemplate = `apiVersion: v1
kind: Service
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/certmanager/certificate.go
Expand Up @@ -36,7 +36,7 @@ func (p *CertManager) GetInput() (input.Input, error) {
return p.Input, nil
}

var certManagerTemplate = `# The following manifests contain a self-signed issuer CR and a certificate CR.
const certManagerTemplate = `# The following manifests contain a self-signed issuer CR and a certificate CR.
# More document can be found at https://docs.cert-manager.io
# WARNING: Targets CertManager 0.11 check https://docs.cert-manager.io/en/latest/tasks/upgrading/index.html for breaking changes
apiVersion: cert-manager.io/v1alpha2
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/certmanager/kustomize.go
Expand Up @@ -36,7 +36,7 @@ func (p *Kustomization) GetInput() (input.Input, error) {
return p.Input, nil
}

var kustomizationTemplate = `resources:
const kustomizationTemplate = `resources:
- certificate.yaml
configurations:
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/certmanager/kustomizeconfig.go
Expand Up @@ -36,7 +36,7 @@ func (p *KustomizeConfig) GetInput() (input.Input, error) {
return p.Input, nil
}

var kustomizeConfigTemplate = `# This configuration is for teaching kustomize how to update name ref and var substitution
const kustomizeConfigTemplate = `# This configuration is for teaching kustomize how to update name ref and var substitution
nameReference:
- kind: Issuer
group: cert-manager.io
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/controller.go
Expand Up @@ -64,7 +64,7 @@ func (a *Controller) GetInput() (input.Input, error) {
return a.Input, nil
}

var controllerTemplate = `{{ .Boilerplate }}
const controllerTemplate = `{{ .Boilerplate }}
package controllers
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaffold/v2/controller_suitetest.go
Expand Up @@ -61,7 +61,7 @@ func (v *ControllerSuiteTest) Validate() error {
return v.Resource.Validate()
}

var controllerSuiteTestTemplate = `{{ .Boilerplate }}
const controllerSuiteTestTemplate = `{{ .Boilerplate }}
package controllers
Expand Down

0 comments on commit 0742025

Please sign in to comment.