Skip to content

Commit 1057dc5

Browse files
Merge pull request openshift#8027 from barbacbd/CORS-3212-ignition
CORS-3212: CAPG Add ignition for CAPG machines
2 parents 604ae24 + ed26af9 commit 1057dc5

File tree

116 files changed

+78562
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+78562
-364
lines changed

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.21
44

55
require (
66
cloud.google.com/go/monitoring v1.17.0
7+
cloud.google.com/go/storage v1.36.0
78
github.com/AlecAivazis/survey/v2 v2.3.5
89
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
910
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.0-beta.1
@@ -95,7 +96,7 @@ require (
9596
golang.org/x/sync v0.6.0
9697
golang.org/x/sys v0.16.0
9798
golang.org/x/term v0.16.0
98-
google.golang.org/api v0.149.0
99+
google.golang.org/api v0.155.0
99100
google.golang.org/genproto/googleapis/api v0.0.0-20240125205218-1f4bbc51befe
100101
google.golang.org/grpc v1.61.0
101102
gopkg.in/ini.v1 v1.67.0
@@ -120,8 +121,10 @@ require (
120121
)
121122

122123
require (
124+
cloud.google.com/go v0.112.0 // indirect
123125
cloud.google.com/go/compute v1.23.3 // indirect
124126
cloud.google.com/go/compute/metadata v0.2.3 // indirect
127+
cloud.google.com/go/iam v1.1.5 // indirect
125128
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
126129
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.2.0 // indirect
127130
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4 v4.3.0 // indirect
@@ -158,6 +161,7 @@ require (
158161
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
159162
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
160163
github.com/fatih/color v1.16.0 // indirect
164+
github.com/felixge/httpsnoop v1.0.4 // indirect
161165
github.com/fsnotify/fsnotify v1.7.0 // indirect
162166
github.com/go-errors/errors v1.4.2 // indirect
163167
github.com/go-logr/logr v1.4.1 // indirect
@@ -244,6 +248,8 @@ require (
244248
github.com/zclconf/go-cty v1.11.0 // indirect
245249
go.mongodb.org/mongo-driver v1.11.3 // indirect
246250
go.opencensus.io v0.24.0 // indirect
251+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
252+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
247253
go.opentelemetry.io/otel v1.22.0 // indirect
248254
go.opentelemetry.io/otel/metric v1.22.0 // indirect
249255
go.opentelemetry.io/otel/sdk v1.22.0 // indirect

go.sum

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmW
1818
cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg=
1919
cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8=
2020
cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0=
21+
cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM=
22+
cloud.google.com/go v0.112.0/go.mod h1:3jEEVwZ/MHU4djK5t5RHuKOA/GbLddgTdVubX1qnPD4=
2123
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
2224
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
2325
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
@@ -31,6 +33,8 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB
3133
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
3234
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
3335
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
36+
cloud.google.com/go/iam v1.1.5 h1:1jTsCu4bcsNsE4iiqNT5SHwrDRCfRmIaaaVFhRveTJI=
37+
cloud.google.com/go/iam v1.1.5/go.mod h1:rB6P/Ic3mykPbFio+vo7403drjlgvoWfYpJhMXEbzv8=
3438
cloud.google.com/go/monitoring v1.17.0 h1:blrdvF0MkPPivSO041ihul7rFMhXdVp8Uq7F59DKXTU=
3539
cloud.google.com/go/monitoring v1.17.0/go.mod h1:KwSsX5+8PnXv5NJnICZzW2R8pWTis8ypC4zmdRD63Tw=
3640
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
@@ -42,6 +46,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
4246
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
4347
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
4448
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
49+
cloud.google.com/go/storage v1.36.0 h1:P0mOkAcaJxhCTvAkMhxMfrTKiNcub4YmmPBtlhAyTr8=
50+
cloud.google.com/go/storage v1.36.0/go.mod h1:M6M/3V/D3KpzMTJyPOR/HU6n2Si5QdaXYEsng2xgOs8=
4551
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
4652
github.com/AlecAivazis/survey/v2 v2.3.5 h1:A8cYupsAZkjaUmhtTYv3sSqc7LO5mp1XDfqe5E/9wRQ=
4753
github.com/AlecAivazis/survey/v2 v2.3.5/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
@@ -206,6 +212,8 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
206212
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
207213
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
208214
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
215+
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101 h1:7To3pQ+pZo0i3dsWEbinPNFs5gPSBOsJtx3wTT94VBY=
216+
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
209217
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
210218
github.com/containers/image v3.0.2+incompatible h1:B1lqAE8MUPCrsBLE86J0gnXleeRq8zJnQryhiiGQNyE=
211219
github.com/containers/image v3.0.2+incompatible/go.mod h1:8Vtij257IWSanUQKe1tAeNOm2sRVkSqQTVQ1IlwI3+M=
@@ -273,6 +281,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
273281
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
274282
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
275283
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
284+
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
285+
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
276286
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
277287
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
278288
github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI=
@@ -284,6 +294,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM
284294
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
285295
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
286296
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
297+
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
298+
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
287299
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
288300
github.com/form3tech-oss/jwt-go v3.2.3+incompatible h1:7ZaBxOI7TMoYBfyA3cQHErNNyAWIKUMIwqxEtgHOs5c=
289301
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
@@ -501,9 +513,12 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
501513
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
502514
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
503515
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
516+
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
504517
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
505518
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
506519
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
520+
github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw=
521+
github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk=
507522
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
508523
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
509524
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
@@ -970,6 +985,10 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
970985
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
971986
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
972987
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
988+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE=
989+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1/go.mod h1:4UoMYEZOC0yN/sPGH76KPkkU7zgiEWYWL9vwmbnTJPE=
990+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 h1:aFJWCqJMNjENlcleuuOkGAPH82y0yULBScfXcIEdS24=
991+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo=
973992
go.opentelemetry.io/otel v1.22.0 h1:xS7Ku+7yTFvDfDraDIJVpw7XPyuHlB9MCiqqX5mcJ6Y=
974993
go.opentelemetry.io/otel v1.22.0/go.mod h1:eoV4iAi3Ea8LkAEI9+GFT44O6T/D0GWAVFyZVCC6pMI=
975994
go.opentelemetry.io/otel/metric v1.22.0 h1:lypMQnGyJYeuYPhOM/bgjbFM6WE44W1/T45er4d8Hhg=
@@ -1230,6 +1249,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
12301249
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12311250
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
12321251
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1252+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
1253+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
12331254
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
12341255
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
12351256
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
@@ -1253,8 +1274,8 @@ google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34q
12531274
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
12541275
google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU=
12551276
google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94=
1256-
google.golang.org/api v0.149.0 h1:b2CqT6kG+zqJIVKRQ3ELJVLN1PwHZ6DJ3dW8yl82rgY=
1257-
google.golang.org/api v0.149.0/go.mod h1:Mwn1B7JTXrzXtnvmzQE2BD6bYZQ8DShKZDZbeN9I7qI=
1277+
google.golang.org/api v0.155.0 h1:vBmGhCYs0djJttDNynWo44zosHlPvHmA0XiN2zP2DtA=
1278+
google.golang.org/api v0.155.0/go.mod h1:GI5qK5f40kCpHfPn6+YzGAByIKWv8ujFnmoWm7Igduk=
12581279
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
12591280
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
12601281
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package gcp
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"cloud.google.com/go/storage"
9+
"google.golang.org/api/option"
10+
11+
"github.com/openshift/installer/pkg/asset/installconfig"
12+
gcpic "github.com/openshift/installer/pkg/asset/installconfig/gcp"
13+
)
14+
15+
const (
16+
bootstrapIgnitionBucketObjName = "bootstrap.ign"
17+
)
18+
19+
// GetBootstrapStorageName gets the name of the storage bucket for the bootstrap process.
20+
func GetBootstrapStorageName(clusterID string) string {
21+
return fmt.Sprintf("%s-bootstrap-ignition", clusterID)
22+
}
23+
24+
// NewStorageClient creates a new Google storage client.
25+
func NewStorageClient(ctx context.Context) (*storage.Client, error) {
26+
ssn, err := gcpic.GetSession(ctx)
27+
if err != nil {
28+
return nil, fmt.Errorf("failed to get session while creating gcp storage client: %w", err)
29+
}
30+
31+
client, err := storage.NewClient(ctx, option.WithCredentials(ssn.Credentials))
32+
if err != nil {
33+
return nil, fmt.Errorf("failed to create client: %w", err)
34+
}
35+
36+
return client, nil
37+
}
38+
39+
// CreateBucketHandle will create the bucket handle that can be used as a reference for other storage resources.
40+
func CreateBucketHandle(ctx context.Context, bucketName string) (*storage.BucketHandle, error) {
41+
ctx, cancel := context.WithTimeout(ctx, time.Minute*1)
42+
defer cancel()
43+
44+
client, err := NewStorageClient(ctx)
45+
if err != nil {
46+
return nil, fmt.Errorf("failed to create storage client: %w", err)
47+
}
48+
return client.Bucket(bucketName), nil
49+
}
50+
51+
// CreateStorage creates the gcp bucket/storage. The storage bucket does Not include the bucket object. The
52+
// bucket object is created as a separate process/function, so that the two are not tied together, and
53+
// the data stored inside the object can be set at a later time.
54+
func CreateStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketHandle *storage.BucketHandle, clusterID string) error {
55+
labels := map[string]string{}
56+
labels[fmt.Sprintf("kubernetes-io-cluster-%s", clusterID)] = "owned"
57+
for _, label := range ic.Config.GCP.UserLabels {
58+
labels[label.Key] = label.Value
59+
}
60+
61+
bucketAttrs := storage.BucketAttrs{
62+
UniformBucketLevelAccess: storage.UniformBucketLevelAccess{
63+
Enabled: true,
64+
},
65+
Location: ic.Config.GCP.Region,
66+
Labels: labels,
67+
}
68+
69+
ctx, cancel := context.WithTimeout(ctx, time.Minute*1)
70+
defer cancel()
71+
72+
if err := bucketHandle.Create(ctx, ic.Config.GCP.ProjectID, &bucketAttrs); err != nil {
73+
return fmt.Errorf("failed to create bucket: %w", err)
74+
}
75+
return nil
76+
}
77+
78+
// CreateSignedURL creates a signed url and correlates the signed url with a storage bucket.
79+
func CreateSignedURL(handle *storage.BucketHandle, objectName string) (string, error) {
80+
// Signing a URL requires credentials authorized to sign a URL. You can pass
81+
// these in through SignedURLOptions with a Google Access ID with
82+
// iam.serviceAccounts.signBlob permissions.
83+
opts := storage.SignedURLOptions{
84+
Scheme: storage.SigningSchemeV4,
85+
Method: "GET",
86+
Expires: time.Now().Add(time.Minute * 60),
87+
}
88+
89+
// The object has not been created yet. This is ok, it is expected to be created after this call.
90+
// However, if the object is never created this could cause major issues.
91+
url, err := handle.SignedURL(objectName, &opts)
92+
if err != nil {
93+
return "", fmt.Errorf("failed to create a signed url: %w", err)
94+
}
95+
96+
return url, nil
97+
}
98+
99+
// ProvisionBootstrapStorage will provision the required storage bucket and signed url for the bootstrap process.
100+
func ProvisionBootstrapStorage(ctx context.Context, ic *installconfig.InstallConfig, bucketHandle *storage.BucketHandle, clusterID string) (string, error) {
101+
ctx, cancel := context.WithTimeout(ctx, time.Minute*1)
102+
defer cancel()
103+
104+
if err := CreateStorage(ctx, ic, bucketHandle, clusterID); err != nil {
105+
return "", fmt.Errorf("failed to create storage: %w", err)
106+
}
107+
108+
url, err := CreateSignedURL(bucketHandle, bootstrapIgnitionBucketObjName)
109+
if err != nil {
110+
return "", fmt.Errorf("failed to sign url: %w", err)
111+
}
112+
113+
return url, nil
114+
}
115+
116+
// FillBucket will add the contents to the bootstrap storage bucket object.
117+
func FillBucket(ctx context.Context, bucketHandle *storage.BucketHandle, contents string) error {
118+
ctx, cancel := context.WithTimeout(ctx, time.Minute*1)
119+
defer cancel()
120+
121+
objWriter := bucketHandle.Object(bootstrapIgnitionBucketObjName).NewWriter(ctx)
122+
if _, err := fmt.Fprint(objWriter, contents); err != nil {
123+
return fmt.Errorf("failed to store content in bucket object: %w", err)
124+
}
125+
126+
if err := objWriter.Close(); err != nil {
127+
return fmt.Errorf("failed to close bucket object writer: %w", err)
128+
}
129+
130+
return nil
131+
}

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ func createCAPIMachine(name string, dataSecret string, infraID string) *capi.Mac
156156
},
157157
Spec: capi.MachineSpec{
158158
ClusterName: infraID,
159-
// Leave empty until ignition support is added
160-
// Bootstrap: capi.Bootstrap{
161-
// DataSecretName: ptr.To(dataSecret),
162-
// },
159+
Bootstrap: capi.Bootstrap{
160+
DataSecretName: ptr.To(dataSecret),
161+
},
163162
InfrastructureRef: v1.ObjectReference{
164163
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
165164
Kind: "GCPMachine",

pkg/asset/machines/gcp/gcpmachines_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package gcp
33

44
import (
5+
"fmt"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -206,6 +207,8 @@ func getGCPMachineWithSecureBoot() *capg.GCPMachine {
206207
}
207208

208209
func getBaseCapiMachine() *capi.Machine {
210+
dataSecret := fmt.Sprintf("%s-master", "012345678")
211+
209212
capiMachine := &capi.Machine{
210213
ObjectMeta: metav1.ObjectMeta{
211214
Name: "012345678-master-0",
@@ -215,6 +218,9 @@ func getBaseCapiMachine() *capi.Machine {
215218
},
216219
Spec: capi.MachineSpec{
217220
ClusterName: "012345678",
221+
Bootstrap: capi.Bootstrap{
222+
DataSecretName: ptr.To(dataSecret),
223+
},
218224
InfrastructureRef: v1.ObjectReference{
219225
APIVersion: "infrastructure.cluster.x-k8s.io/v1beta1",
220226
Kind: "GCPMachine",

pkg/infrastructure/gcp/clusterapi/clusterapi.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package clusterapi
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/sirupsen/logrus"
89
capg "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1"
910
"sigs.k8s.io/controller-runtime/pkg/client"
1011

12+
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
13+
"github.com/openshift/installer/pkg/asset/ignition/bootstrap/gcp"
1114
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
1215
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
1316
"github.com/openshift/installer/pkg/types"
@@ -41,7 +44,41 @@ func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionIn
4144
// added to a bucket. A signed url is generated to point to the bucket and the ignition data will be
4245
// updated to point to the url. This is also allows for bootstrap data to be edited after its initial creation.
4346
func (p Provider) Ignition(ctx context.Context, in clusterapi.IgnitionInput) ([]byte, error) {
44-
return nil, nil
47+
// Create the bucket and presigned url. The url is generated using a known/expected name so that the
48+
// url can be retrieved from the api by this name.
49+
ctx, cancel := context.WithTimeout(ctx, time.Minute*2)
50+
defer cancel()
51+
52+
bucketName := gcp.GetBootstrapStorageName(in.InfraID)
53+
bucketHandle, err := gcp.CreateBucketHandle(ctx, bucketName)
54+
if err != nil {
55+
return nil, fmt.Errorf("failed to create bucket handle %s: %w", bucketName, err)
56+
}
57+
58+
url, err := gcp.ProvisionBootstrapStorage(ctx, in.InstallConfig, bucketHandle, in.InfraID)
59+
if err != nil {
60+
return nil, fmt.Errorf("ignition failed to provision storage: %w", err)
61+
}
62+
editedIgnitionBytes, err := EditIgnition(ctx, in)
63+
if err != nil {
64+
return nil, fmt.Errorf("failed to edit bootstrap ignition: %w", err)
65+
}
66+
67+
ignitionBytes := in.BootstrapIgnData
68+
if editedIgnitionBytes != nil {
69+
ignitionBytes = editedIgnitionBytes
70+
}
71+
72+
if err := gcp.FillBucket(ctx, bucketHandle, string(ignitionBytes)); err != nil {
73+
return nil, fmt.Errorf("ignition failed to fill bucket: %w", err)
74+
}
75+
76+
ignShim, err := bootstrap.GenerateIgnitionShimWithCertBundleAndProxy(url, in.InstallConfig.Config.AdditionalTrustBundle, in.InstallConfig.Config.Proxy)
77+
if err != nil {
78+
return nil, fmt.Errorf("failed to create ignition shim: %w", err)
79+
}
80+
81+
return ignShim, nil
4582
}
4683

4784
// InfraReady is called once cluster.Status.InfrastructureReady

0 commit comments

Comments
 (0)