@@ -13,6 +13,8 @@ import (
1313
1414 "github.com/openshift/installer/pkg/asset"
1515 "github.com/openshift/installer/pkg/asset/agent"
16+ "github.com/openshift/installer/pkg/asset/agent/joiner"
17+ "github.com/openshift/installer/pkg/asset/agent/workflow"
1618 "github.com/openshift/installer/pkg/asset/ignition/bootstrap"
1719 "github.com/openshift/installer/pkg/asset/releaseimage"
1820 "github.com/openshift/installer/pkg/types"
@@ -128,35 +130,84 @@ func (*RegistriesConf) Name() string {
128130// the asset.
129131func (* RegistriesConf ) Dependencies () []asset.Asset {
130132 return []asset.Asset {
133+ & workflow.AgentWorkflow {},
134+ & joiner.ClusterInfo {},
131135 & agent.OptionalInstallConfig {},
132136 & releaseimage.Image {},
133137 }
134138}
135139
136140// Generate generates the registries.conf file from install-config.
137141func (i * RegistriesConf ) Generate (dependencies asset.Parents ) error {
138-
142+ agentWorkflow := & workflow.AgentWorkflow {}
143+ clusterInfo := & joiner.ClusterInfo {}
139144 installConfig := & agent.OptionalInstallConfig {}
140145 releaseImage := & releaseimage.Image {}
141- dependencies .Get (installConfig , releaseImage )
146+ dependencies .Get (installConfig , releaseImage , agentWorkflow , clusterInfo )
147+
148+ var imageDigestSources []types.ImageDigestSource
149+ var deprecatedImageContentSources []types.ImageContentSource
150+ var image string
151+
152+ switch agentWorkflow .Workflow {
153+ case workflow .AgentWorkflowTypeInstall :
154+ if installConfig .Supplied {
155+ imageDigestSources = installConfig .Config .ImageDigestSources
156+ deprecatedImageContentSources = installConfig .Config .DeprecatedImageContentSources
157+ }
158+ image = releaseImage .PullSpec
159+
160+ case workflow .AgentWorkflowTypeAddNodes :
161+ imageDigestSources = clusterInfo .ImageDigestSources
162+ deprecatedImageContentSources = clusterInfo .DeprecatedImageContentSources
163+ image = clusterInfo .ReleaseImage
142164
143- if ! installConfig .Supplied || len (installConfig .Config .DeprecatedImageContentSources ) == 0 && len (installConfig .Config .ImageDigestSources ) == 0 {
165+ default :
166+ return fmt .Errorf ("AgentWorkflowType value not supported: %s" , agentWorkflow .Workflow )
167+ }
168+
169+ if len (deprecatedImageContentSources ) == 0 && len (imageDigestSources ) == 0 {
144170 return i .generateDefaultRegistriesConf ()
145171 }
146172
147- if len (installConfig .Config .DeprecatedImageContentSources ) != 0 && len (installConfig .Config .ImageDigestSources ) != 0 {
173+ err := i .generateRegistriesConf (imageDigestSources , deprecatedImageContentSources )
174+ if err != nil {
175+ return err
176+ }
177+
178+ if ! i .releaseImageIsSameInRegistriesConf (image ) {
179+ logrus .Warnf (fmt .Sprintf ("The imageDigestSources configuration in install-config.yaml should have at least one source field matching the releaseImage value %s" , releaseImage .PullSpec ))
180+ }
181+
182+ registriesData , err := toml .Marshal (i .Config )
183+ if err != nil {
184+ return err
185+ }
186+
187+ i .File = & asset.File {
188+ Filename : RegistriesConfFilename ,
189+ Data : registriesData ,
190+ }
191+
192+ return nil
193+ }
194+
195+ func (i * RegistriesConf ) generateRegistriesConf (imageDigestSources []types.ImageDigestSource , deprecatedImageContentSources []types.ImageContentSource ) error {
196+
197+ if len (deprecatedImageContentSources ) != 0 && len (imageDigestSources ) != 0 {
148198 return fmt .Errorf ("invalid install-config.yaml, cannot set imageContentSources and imageDigestSources at the same time" )
149199 }
150200
201+ digestMirrorSources := []types.ImageDigestSource {}
202+ if len (deprecatedImageContentSources ) > 0 {
203+ digestMirrorSources = bootstrap .ContentSourceToDigestMirror (deprecatedImageContentSources )
204+ } else if len (imageDigestSources ) > 0 {
205+ digestMirrorSources = append (digestMirrorSources , imageDigestSources ... )
206+ }
207+
151208 registries := & sysregistriesv2.V2RegistriesConf {
152209 Registries : []sysregistriesv2.Registry {},
153210 }
154- digestMirrorSources := []types.ImageDigestSource {}
155- if len (installConfig .Config .DeprecatedImageContentSources ) > 0 {
156- digestMirrorSources = bootstrap .ContentSourceToDigestMirror (installConfig .Config .DeprecatedImageContentSources )
157- } else if len (installConfig .Config .ImageDigestSources ) > 0 {
158- digestMirrorSources = append (digestMirrorSources , installConfig .Config .ImageDigestSources ... )
159- }
160211 for _ , group := range bootstrap .MergedMirrorSets (digestMirrorSources ) {
161212 if len (group .Mirrors ) == 0 {
162213 continue
@@ -173,20 +224,6 @@ func (i *RegistriesConf) Generate(dependencies asset.Parents) error {
173224 i .Config = registries
174225 i .setMirrorConfig (i .Config )
175226
176- if ! i .releaseImageIsSameInRegistriesConf (releaseImage .PullSpec ) {
177- logrus .Warnf (fmt .Sprintf ("The imageDigestSources configuration in install-config.yaml should have at least one source field matching the releaseImage value %s" , releaseImage .PullSpec ))
178- }
179-
180- registriesData , err := toml .Marshal (registries )
181- if err != nil {
182- return err
183- }
184-
185- i .File = & asset.File {
186- Filename : RegistriesConfFilename ,
187- Data : registriesData ,
188- }
189-
190227 return nil
191228}
192229
0 commit comments