github.com/jenkins-x/jx/v2@v2.1.155/pkg/config/helm_values.go (about) 1 package config 2 3 import ( 4 "fmt" 5 6 "github.com/ghodss/yaml" 7 "github.com/spf13/cobra" 8 ) 9 10 // ExposeDefaultURLTemplate is the default url template format needed by exposecontroller to create ingress rules that work with wiuldcard certs 11 const ExposeDefaultURLTemplate = "{{.Service}}-{{.Namespace}}.{{.Domain}}" 12 13 type ExposeControllerConfig struct { 14 Domain string `json:"domain,omitempty"` 15 Exposer string `json:"exposer,omitempty"` 16 HTTP string `json:"http,omitempty"` 17 TLSAcme string `json:"tlsacme,omitempty"` 18 PathMode string `json:"pathMode,omitempty"` 19 URLTemplate string `json:"urltemplate,omitempty"` 20 IngressClass string `json:"ingressClass,omitempty"` 21 TLSSecretName string `json:"tlsSecretName,omitempty"` 22 } 23 type ExposeController struct { 24 Config ExposeControllerConfig `json:"config,omitempty"` 25 Annotations map[string]string `json:"Annotations,omitempty"` 26 Production bool `json:"production,omitempty"` 27 } 28 29 type JenkinsValuesConfig struct { 30 Servers JenkinsServersValuesConfig `json:"Servers,omitempty"` 31 Enabled *bool `json:"enabled,omitempty"` 32 } 33 34 type ProwValuesConfig struct { 35 User string `json:"user,omitempty"` 36 HMACtoken string `json:"hmacToken,omitempty"` 37 OAUTHtoken string `json:"oauthToken,omitempty"` 38 } 39 40 type JenkinsServersValuesConfig struct { 41 Gitea []JenkinsGiteaServersValuesConfig `json:"Gitea,omitempty"` 42 GHE []JenkinsGithubServersValuesConfig `json:"GHE,omitempty"` 43 Global JenkinsServersGlobalConfig `json:"Global,omitempty"` 44 } 45 46 type JenkinsServersGlobalConfig struct { 47 EnvVars map[string]string `json:"EnvVars,omitempty"` 48 } 49 50 type JenkinsGiteaServersValuesConfig struct { 51 Name string `json:"Name,omitempty"` 52 Url string `json:"Url,omitempty"` 53 Credential string `json:"Credential,omitempty"` 54 } 55 56 type JenkinsGithubServersValuesConfig struct { 57 Name string `json:"Name,omitempty"` 58 Url string `json:"Url,omitempty"` 59 } 60 61 type JenkinsPipelineSecretsValuesConfig struct { 62 DockerConfig string `json:"DockerConfig,flow,omitempty"` 63 } 64 65 // EnabledConfig to configure the feature on/off 66 type EnabledConfig struct { 67 Enabled bool `json:"enabled"` 68 } 69 70 type HelmValuesConfig struct { 71 ExposeController *ExposeController `json:"expose,omitempty"` 72 Jenkins JenkinsValuesConfig `json:"jenkins,omitempty"` 73 Prow ProwValuesConfig `json:"prow,omitempty"` 74 PipelineSecrets JenkinsPipelineSecretsValuesConfig `json:"PipelineSecrets,omitempty"` 75 ControllerBuild *EnabledConfig `json:"controllerbuild,omitempty"` 76 ControllerWorkflow *EnabledConfig `json:"controllerworkflow,omitempty"` 77 DockerRegistryEnabled *EnabledConfig `json:"docker-registry,omitempty"` 78 DockerRegistry string `json:"dockerRegistry,omitempty"` 79 } 80 81 type HelmValuesConfigService struct { 82 FileName string 83 Config HelmValuesConfig 84 } 85 86 // GetOrCreateFirstGitea returns the first gitea server creating one if required 87 func (c *JenkinsServersValuesConfig) GetOrCreateFirstGitea() *JenkinsGiteaServersValuesConfig { 88 if len(c.Gitea) == 0 { 89 c.Gitea = []JenkinsGiteaServersValuesConfig{ 90 { 91 Name: "gitea", 92 Credential: "jenkins-x-git", 93 }, 94 } 95 } 96 return &c.Gitea[0] 97 } 98 99 func (c *HelmValuesConfig) AddExposeControllerValues(cmd *cobra.Command, ignoreDomain bool) { 100 if !ignoreDomain { 101 cmd.Flags().StringVarP(&c.ExposeController.Config.Domain, "domain", "", "", "Domain to expose ingress endpoints. Example: jenkinsx.io") 102 } 103 keepJob := false 104 105 cmd.Flags().StringVarP(&c.ExposeController.Config.HTTP, "http", "", "true", "Toggle creating http or https ingress rules") 106 cmd.Flags().StringVarP(&c.ExposeController.Config.Exposer, "exposer", "", "Ingress", "Used to describe which strategy exposecontroller should use to access applications") 107 cmd.Flags().StringVarP(&c.ExposeController.Config.TLSAcme, "tls-acme", "", "", "Used to enable automatic TLS for ingress") 108 cmd.Flags().StringVarP(&c.ExposeController.Config.URLTemplate, "urltemplate", "", "", "For ingress; exposers can set the urltemplate to expose") 109 cmd.Flags().StringVarP(&c.ExposeController.Config.IngressClass, "ingress-class", "", "", "Used to set the ingress.class annotation in exposecontroller created ingress") 110 cmd.Flags().BoolVarP(&keepJob, "keep-exposecontroller-job", "", false, "Prevents Helm deleting the exposecontroller Job and Pod after running. Useful for debugging exposecontroller logs but you will need to manually delete the job if you update an environment") 111 112 // Todo: Again recommendation to use a command which is deprecated. On another note, what is the policy for removing deprecated flags? No mention of a date 113 cmd.Flags().MarkDeprecated("http", "please use `jx upgrade ingress` after install instead") //nolint:errcheck 114 cmd.Flags().MarkDeprecated("tls-acme", "please use `jx upgrade ingress` after install instead") //nolint:errcheck 115 116 annotations := make(map[string]string) 117 annotations["helm.sh/hook"] = "post-install,post-upgrade" 118 if !keepJob { 119 annotations["helm.sh/hook-delete-policy"] = "hook-succeeded" 120 } 121 c.ExposeController.Annotations = annotations 122 } 123 124 func (c HelmValuesConfig) String() (string, error) { 125 b, err := yaml.Marshal(c) 126 if err != nil { 127 return "", fmt.Errorf("failed to marshall helm values %v", err) 128 } 129 return string(b), nil 130 }