@@ -2,13 +2,18 @@ package bootstrap
22
33import (
44 "bytes"
5+ "context"
56 "errors"
67 "fmt"
78 "io"
89 "os"
910 "path/filepath"
11+ "time"
1012
13+ "github.com/openshift/api/features"
1114 imagev1 "github.com/openshift/api/image/v1"
15+ "github.com/openshift/api/machineconfiguration/v1alpha1"
16+ "github.com/openshift/machine-config-operator/pkg/controller/osimagestream"
1217 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1318
1419 corev1 "k8s.io/api/core/v1"
@@ -68,7 +73,7 @@ func (b *Bootstrap) Run(destDir string) error {
6873 return err
6974 }
7075
71- psraw , err := getPullSecretFromSecret (psfraw )
76+ pullSecret , err := getValidatePullSecretFromBytes (psfraw )
7277 if err != nil {
7378 return err
7479 }
@@ -195,15 +200,46 @@ func (b *Bootstrap) Run(destDir string) error {
195200 return fmt .Errorf ("error creating feature gates handler: %w" , err )
196201 }
197202
198- iconfigs , err := template .RunBootstrap (b .templatesDir , cconfig , psraw , apiServer )
203+ var osImageStream * v1alpha1.OSImageStream
204+ if fgHandler .Enabled (features .FeatureGateOSStreams ) {
205+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
206+ defer cancel ()
207+
208+ // TODO @pablintino we need to change the factory API to avoid passing that cmLister at bootstrap
209+ osImageStream , err = osimagestream .BuildOsImageStreamBootstrap (ctx ,
210+ pullSecret ,
211+ cconfig ,
212+ imageStream ,
213+ & osimagestream.OSImageTuple {
214+ OSImage : cconfig .Spec .BaseOSContainerImage ,
215+ OSExtensionsImage : cconfig .Spec .BaseOSExtensionsContainerImage ,
216+ },
217+ osimagestream .NewDefaultStreamSourceFactory (nil , & osimagestream.DefaultImagesInspectorFactory {}),
218+ )
219+ if err != nil {
220+ return fmt .Errorf ("error inspecting available OSImageStreams: %w" , err )
221+ }
222+
223+ // For sanity reasons we override the ControllerConfig URLs with the default stream ones
224+ defaultStreamSet , err := osimagestream .GetOSImageStreamSetByName (osImageStream , "" )
225+ if err != nil {
226+ // Should never happen
227+ return fmt .Errorf ("error getting default OSImageStreamSet: %w" , err )
228+ }
229+ cconfig .Spec .BaseOSContainerImage = string (defaultStreamSet .OSImage )
230+ cconfig .Spec .BaseOSExtensionsContainerImage = string (defaultStreamSet .OSExtensionsImage )
231+ }
232+
233+ pullSecretBytes := pullSecret .Data [corev1 .DockerConfigJsonKey ]
234+ iconfigs , err := template .RunBootstrap (b .templatesDir , cconfig , pools , pullSecretBytes , apiServer , osImageStream )
199235 if err != nil {
200236 return err
201237 }
202238 klog .Infof ("Successfully generated MachineConfigs from templates." )
203239
204240 configs = append (configs , iconfigs ... )
205241
206- rconfigs , err := containerruntimeconfig .RunImageBootstrap (b .templatesDir , cconfig , pools , icspRules , idmsRules , itmsRules , imgCfg , clusterImagePolicies , imagePolicies , fgHandler )
242+ rconfigs , err := containerruntimeconfig .RunImageBootstrap (b .templatesDir , cconfig , pools , icspRules , idmsRules , itmsRules , imgCfg , clusterImagePolicies , imagePolicies , fgHandler , osImageStream )
207243 if err != nil {
208244 return err
209245 }
@@ -212,7 +248,7 @@ func (b *Bootstrap) Run(destDir string) error {
212248 configs = append (configs , rconfigs ... )
213249
214250 if len (crconfigs ) > 0 {
215- containerRuntimeConfigs , err := containerruntimeconfig .RunContainerRuntimeBootstrap (b .templatesDir , crconfigs , cconfig , pools )
251+ containerRuntimeConfigs , err := containerruntimeconfig .RunContainerRuntimeBootstrap (b .templatesDir , crconfigs , cconfig , pools , osImageStream )
216252 if err != nil {
217253 return err
218254 }
@@ -221,7 +257,7 @@ func (b *Bootstrap) Run(destDir string) error {
221257 klog .Infof ("Successfully generated MachineConfigs from containerruntime." )
222258
223259 if featureGate != nil {
224- featureConfigs , err := kubeletconfig .RunFeatureGateBootstrap (b .templatesDir , fgHandler , nodeConfig , cconfig , pools , apiServer )
260+ featureConfigs , err := kubeletconfig .RunFeatureGateBootstrap (b .templatesDir , fgHandler , nodeConfig , cconfig , pools , apiServer , osImageStream )
225261 if err != nil {
226262 return err
227263 }
@@ -238,7 +274,7 @@ func (b *Bootstrap) Run(destDir string) error {
238274 }
239275 }
240276 if nodeConfig != nil {
241- nodeConfigs , err := kubeletconfig .RunNodeConfigBootstrap (b .templatesDir , fgHandler , cconfig , nodeConfig , pools , apiServer )
277+ nodeConfigs , err := kubeletconfig .RunNodeConfigBootstrap (b .templatesDir , fgHandler , cconfig , nodeConfig , pools , apiServer , osImageStream )
242278 if err != nil {
243279 return err
244280 }
@@ -247,7 +283,7 @@ func (b *Bootstrap) Run(destDir string) error {
247283 klog .Infof ("Successfully generated MachineConfigs from node.Configs." )
248284
249285 if len (kconfigs ) > 0 {
250- kconfigs , err := kubeletconfig .RunKubeletBootstrap (b .templatesDir , kconfigs , cconfig , fgHandler , nodeConfig , pools , apiServer )
286+ kconfigs , err := kubeletconfig .RunKubeletBootstrap (b .templatesDir , kconfigs , cconfig , fgHandler , nodeConfig , pools , apiServer , osImageStream )
251287 if err != nil {
252288 return err
253289 }
@@ -267,7 +303,7 @@ func (b *Bootstrap) Run(destDir string) error {
267303 klog .Infof ("Successfully created %d pre-built image component MachineConfigs for hybrid OCL." , len (preBuiltImageMCs ))
268304 }
269305
270- fpools , gconfigs , err := render .RunBootstrap (pools , configs , cconfig )
306+ fpools , gconfigs , err := render .RunBootstrap (pools , configs , cconfig , osImageStream )
271307 if err != nil {
272308 return err
273309 }
@@ -345,16 +381,12 @@ func (b *Bootstrap) Run(destDir string) error {
345381 return err
346382 }
347383
348- if imageStream != nil {
349- klog .Infof ("ImageStream found!" )
350- }
351-
352384 klog .Infof ("writing the following controllerConfig to disk: %s" , string (buf .Bytes ()))
353385 return os .WriteFile (filepath .Join (cconfigDir , "machine-config-controller.yaml" ), buf .Bytes (), 0o664 )
354386
355387}
356388
357- func getPullSecretFromSecret (sData []byte ) ([] byte , error ) {
389+ func getValidatePullSecretFromBytes (sData []byte ) (* corev1. Secret , error ) {
358390 obji , err := runtime .Decode (kscheme .Codecs .UniversalDecoder (corev1 .SchemeGroupVersion ), sData )
359391 if err != nil {
360392 return nil , err
@@ -366,7 +398,7 @@ func getPullSecretFromSecret(sData []byte) ([]byte, error) {
366398 if s .Type != corev1 .SecretTypeDockerConfigJson {
367399 return nil , fmt .Errorf ("expected secret type %s found %s" , corev1 .SecretTypeDockerConfigJson , s .Type )
368400 }
369- return s . Data [ corev1 . DockerConfigJsonKey ] , nil
401+ return s , nil
370402}
371403
372404type manifest struct {
0 commit comments