22package aws
33
44import (
5+ "bytes"
6+ "encoding/pem"
57 "fmt"
8+ "strings"
69
10+ "github.com/vincent-petithory/dataurl"
711 v1 "k8s.io/api/core/v1"
812 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
913 "k8s.io/apimachinery/pkg/util/sets"
@@ -24,6 +28,7 @@ type MachineInput struct {
2428 Subnets map [string ]string
2529 Tags capa.Tags
2630 PublicIP bool
31+ Ignition * capa.Ignition
2732}
2833
2934// GenerateMachines returns manifests and runtime objects to provision the control plane (including bootstrap, if applicable) nodes using CAPI.
@@ -70,7 +75,7 @@ func GenerateMachines(clusterID string, in *MachineInput) ([]*asset.RuntimeFile,
7075 },
7176 },
7277 Spec : capa.AWSMachineSpec {
73- Ignition : & capa .Ignition { Version : "3.2" } ,
78+ Ignition : in .Ignition ,
7479 UncompressedUserData : ptr .To (true ),
7580 InstanceType : mpool .InstanceType ,
7681 AMI : capa.AMIReference {ID : ptr .To (mpool .AMIID )},
@@ -160,3 +165,62 @@ func CapaTagsFromUserTags(clusterID string, usertags map[string]string) (capa.Ta
160165 }
161166 return tags , nil
162167}
168+
169+ // CapaIgnitionWithCertBundleAndProxy generates CAPA ignition config with cert and proxy information.
170+ func CapaIgnitionWithCertBundleAndProxy (userCA string , proxy * types.Proxy ) (* capa.Ignition , error ) {
171+ carefs , err := parseCertificateBundle ([]byte (userCA ))
172+ if err != nil {
173+ return nil , err
174+ }
175+ return & capa.Ignition {
176+ Version : "3.2" ,
177+ TLS : & capa.IgnitionTLS {
178+ CASources : carefs ,
179+ },
180+ Proxy : capaIgnitionProxy (proxy ),
181+ }, nil
182+ }
183+
184+ // TODO: try to share this code with ignition.bootstrap package?
185+ // parseCertificateBundle loads each certificate in the bundle to the CAPA
186+ // carrier type, ignoring any invisible character before, after and in between
187+ // certificates.
188+ func parseCertificateBundle (userCA []byte ) ([]capa.IgnitionCASource , error ) {
189+ userCA = bytes .TrimSpace (userCA )
190+
191+ var carefs []capa.IgnitionCASource
192+ for len (userCA ) > 0 {
193+ var block * pem.Block
194+ block , userCA = pem .Decode (userCA )
195+ if block == nil {
196+ return nil , fmt .Errorf ("unable to parse certificate, please check the certificates" )
197+ }
198+
199+ carefs = append (carefs , capa .IgnitionCASource (dataurl .EncodeBytes (pem .EncodeToMemory (block ))))
200+
201+ userCA = bytes .TrimSpace (userCA )
202+ }
203+
204+ return carefs , nil
205+ }
206+
207+ func capaIgnitionProxy (proxy * types.Proxy ) * capa.IgnitionProxy {
208+ capaProxy := & capa.IgnitionProxy {}
209+ if proxy == nil {
210+ return capaProxy
211+ }
212+ if httpProxy := proxy .HTTPProxy ; httpProxy != "" {
213+ capaProxy .HTTPProxy = & httpProxy
214+ }
215+ if httpsProxy := proxy .HTTPSProxy ; httpsProxy != "" {
216+ capaProxy .HTTPSProxy = & httpsProxy
217+ }
218+ capaProxy .NoProxy = make ([]capa.IgnitionNoProxy , 0 , len (proxy .NoProxy ))
219+ if noProxy := proxy .NoProxy ; noProxy != "" {
220+ noProxySplit := strings .Split (noProxy , "," )
221+ for _ , p := range noProxySplit {
222+ capaProxy .NoProxy = append (capaProxy .NoProxy , capa .IgnitionNoProxy (p ))
223+ }
224+ }
225+ return capaProxy
226+ }
0 commit comments