@@ -31,7 +31,9 @@ import (
3131 "github.com/spf13/cobra"
3232
3333 corev1 "k8s.io/api/core/v1"
34+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3435 "k8s.io/apimachinery/pkg/util/yaml"
36+ sigsyaml "sigs.k8s.io/yaml"
3537
3638 operatorv1 "github.com/openshift/api/operator/v1"
3739
@@ -41,36 +43,6 @@ import (
4143 "github.com/openshift/cloud-credential-operator/pkg/operator/utils"
4244)
4345
44- const (
45- podYamlFilename = "cloud-credential-operator-pod.yaml"
46-
47- podTemplate = `apiVersion: v1
48- kind: Pod
49- metadata:
50- name: cloud-credential-operator
51- namespace: openshift-cloud-credential-operator
52- spec:
53- containers:
54- - command:
55- - /usr/bin/cloud-credential-operator
56- args:
57- - operator
58- - --log-level=debug
59- - --kubeconfig=/etc/kubernetes/secrets/kubeconfig
60- image: %s
61- imagePullPolicy: IfNotPresent
62- name: cloud-credential-operator
63- volumeMounts:
64- - mountPath: /etc/kubernetes/secrets
65- name: secrets
66- readOnly: true
67- hostNetwork: true
68- volumes:
69- - hostPath:
70- path: /etc/kubernetes/bootstrap-secrets
71- name: secrets`
72- )
73-
7446const (
7547 manifestsDir = "manifests"
7648 bootstrapManifestsDir = "bootstrap-manifests"
@@ -81,6 +53,7 @@ const (
8153 installConfigKeyName = "install-config"
8254
8355 operatorConfigFilename = "cco-operator-config.yaml"
56+ podYamlFilename = "cloud-credential-operator-pod.yaml"
8457)
8558
8659var (
@@ -110,6 +83,54 @@ spec:
11083 ccoImage string
11184 logLevel string
11285 }
86+
87+ staticPod = & corev1.Pod {
88+ TypeMeta : metav1.TypeMeta {
89+ APIVersion : "v1" ,
90+ Kind : "Pod" ,
91+ },
92+ ObjectMeta : metav1.ObjectMeta {
93+ Name : "cloud-credential-operator" ,
94+ Namespace : "openshift-cloud-credential-operator" ,
95+ },
96+ Spec : corev1.PodSpec {
97+ Containers : []corev1.Container {{
98+ Args : []string {
99+ "operator" ,
100+ "--log-level=debug" ,
101+ "--kubeconfig=/etc/kubernetes/secrets/kubeconfig" ,
102+ },
103+ Command : []string {"/usr/bin/cloud-credential-operator" },
104+ ImagePullPolicy : corev1 .PullIfNotPresent ,
105+ Name : "cloud-credential-operator" ,
106+ VolumeMounts : []corev1.VolumeMount {{
107+ MountPath : "/etc/pki/ca-trust/extracted/pem" ,
108+ Name : "cco-trusted-ca" ,
109+ ReadOnly : true ,
110+ }, {
111+ MountPath : "/etc/kubernetes/secrets" ,
112+ Name : "secrets" ,
113+ ReadOnly : true ,
114+ }},
115+ }},
116+ HostNetwork : true ,
117+ Volumes : []corev1.Volume {{
118+ Name : "cco-trusted-ca" ,
119+ VolumeSource : corev1.VolumeSource {
120+ HostPath : & corev1.HostPathVolumeSource {
121+ Path : "/etc/pki/ca-trust/extracted/pem" ,
122+ },
123+ },
124+ }, {
125+ Name : "secrets" ,
126+ VolumeSource : corev1.VolumeSource {
127+ HostPath : & corev1.HostPathVolumeSource {
128+ Path : "/etc/kubernetes/bootstrap-secrets" ,
129+ },
130+ },
131+ }},
132+ },
133+ }
113134)
114135
115136type operatorTemplateVars struct {
@@ -208,9 +229,38 @@ func render() error {
208229 if effectiveMode != operatorv1 .CloudCredentialsModeManual {
209230 log .Info ("Rendering static pod" )
210231 podPath := filepath .Join (ccoRenderDir , bootstrapManifestsDir , podYamlFilename )
211- podContent := fmt .Sprintf (podTemplate , renderOpts .ccoImage )
212- log .Infof ("writing file: %s" , podPath )
213- err := os .WriteFile (podPath , []byte (podContent ), 0644 )
232+
233+ staticPod .Spec .Containers [0 ].Image = renderOpts .ccoImage
234+
235+ if installConfig .Proxy != nil {
236+ if installConfig .Proxy .HTTPProxy != "" {
237+ staticPod .Spec .Containers [0 ].Env = append (staticPod .Spec .Containers [0 ].Env , corev1.EnvVar {
238+ Name : "HTTP_PROXY" ,
239+ Value : installConfig .Proxy .HTTPProxy ,
240+ })
241+ }
242+
243+ if installConfig .Proxy .HTTPSProxy != "" {
244+ staticPod .Spec .Containers [0 ].Env = append (staticPod .Spec .Containers [0 ].Env , corev1.EnvVar {
245+ Name : "HTTPS_PROXY" ,
246+ Value : installConfig .Proxy .HTTPSProxy ,
247+ })
248+ }
249+
250+ if installConfig .Proxy .NoProxy != "" {
251+ staticPod .Spec .Containers [0 ].Env = append (staticPod .Spec .Containers [0 ].Env , corev1.EnvVar {
252+ Name : "NO_PROXY" ,
253+ Value : installConfig .Proxy .NoProxy ,
254+ })
255+ }
256+ }
257+
258+ podContent , err := sigsyaml .Marshal (& staticPod )
259+ if err != nil {
260+ return errors .Wrap (err , "failed to encode yaml" )
261+ }
262+
263+ err = writeFile (podPath , podContent )
214264 if err != nil {
215265 return errors .Wrap (err , "failed to write file" )
216266 }
@@ -286,9 +336,23 @@ func isDisabledViaConfigmap() bool {
286336 return disabled
287337}
288338
339+ type Proxy struct {
340+ // +optional
341+ HTTPProxy string `json:"httpProxy,omitempty"`
342+
343+ // +optional
344+ HTTPSProxy string `json:"httpsProxy,omitempty"`
345+
346+ // +optional
347+ NoProxy string `json:"noProxy,omitempty"`
348+ }
349+
289350type basicInstallConfig struct {
290351 CredentialsMode operatorv1.CloudCredentialsMode `json:"credentialsMode"`
291352 Capabilities * v1.ClusterVersionCapabilitiesSpec `json:"capabilities"`
353+
354+ // +optional
355+ Proxy * Proxy `json:"proxy,omitempty"`
292356}
293357
294358func getInstallConfig () (* basicInstallConfig , error ) {
0 commit comments