Skip to content

Commit 73a76ac

Browse files
committed
pkg/clusterapi/system: run from metadata
This commit removes the dependency on the installconfig and uses metadata instead. This will make it easier to restart the capi system at any point because we will not need to retrieve the installconfig asset. At the moment, the standalone bootstrap destroy command is the only example of when we will need to restart the CAPI control plane.
1 parent d263ca5 commit 73a76ac

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

pkg/clusterapi/system.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818
"sigs.k8s.io/controller-runtime/pkg/envtest"
1919

20+
"github.com/openshift/installer/cmd/openshift-install/command"
2021
"github.com/openshift/installer/data"
21-
"github.com/openshift/installer/pkg/asset/installconfig"
22+
"github.com/openshift/installer/pkg/asset/cluster/metadata"
23+
azic "github.com/openshift/installer/pkg/asset/installconfig/azure"
2224
gcpic "github.com/openshift/installer/pkg/asset/installconfig/gcp"
2325
powervsic "github.com/openshift/installer/pkg/asset/installconfig/powervs"
2426
"github.com/openshift/installer/pkg/clusterapi/internal/process"
@@ -49,7 +51,7 @@ const (
4951

5052
// Interface is the interface for the cluster-api system.
5153
type Interface interface {
52-
Run(ctx context.Context, installConfig *installconfig.InstallConfig) error
54+
Run(ctx context.Context) error
5355
State() SystemState
5456
Client() client.Client
5557
Teardown()
@@ -78,7 +80,7 @@ type system struct {
7880
}
7981

8082
// Run launches the cluster-api system.
81-
func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallConfig) error {
83+
func (c *system) Run(ctx context.Context) error {
8284
c.Lock()
8385
defer c.Unlock()
8486

@@ -121,9 +123,19 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
121123
},
122124
}
123125

126+
metadata, err := metadata.Load(command.RootOpts.Dir)
127+
if err != nil {
128+
return fmt.Errorf("failed to load metadata: %w", err)
129+
}
130+
131+
platform := metadata.Platform()
132+
if platform == "" {
133+
return fmt.Errorf("no platform configured in metadata")
134+
}
135+
124136
// Create the infrastructure controllers.
125137
// Only add the controllers for the platform we are deploying to.
126-
switch platform := installConfig.Config.Platform.Name(); platform {
138+
switch platform {
127139
case aws.Name:
128140
controller := c.getInfrastructureController(
129141
&AWS,
@@ -137,7 +149,7 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
137149
},
138150
map[string]string{},
139151
)
140-
if cfg := installConfig.Config.AWS; cfg != nil && len(cfg.ServiceEndpoints) > 0 {
152+
if cfg := metadata.AWS; cfg != nil && len(cfg.ServiceEndpoints) > 0 {
141153
endpoints := make([]string, 0, len(cfg.ServiceEndpoints))
142154
// CAPA expects name=url pairs of service endpoints
143155
for _, endpoint := range cfg.ServiceEndpoints {
@@ -147,9 +159,13 @@ func (c *system) Run(ctx context.Context, installConfig *installconfig.InstallCo
147159
}
148160
controllers = append(controllers, controller)
149161
case azure.Name:
150-
session, err := installConfig.Azure.Session()
162+
cloudName := metadata.Azure.CloudName
163+
if cloudName == "" {
164+
cloudName = azure.PublicCloud
165+
}
166+
session, err := azic.GetSession(cloudName, metadata.Azure.ARMEndpoint)
151167
if err != nil {
152-
return fmt.Errorf("failed to create azure session: %w", err)
168+
return fmt.Errorf("unable to retrieve azure session: %w", err)
153169
}
154170

155171
controllers = append(controllers,

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
132132
// Run the CAPI system.
133133
timer.StartTimer(infrastructureStage)
134134
capiSystem := clusterapi.System()
135-
if err := capiSystem.Run(ctx, installConfig); err != nil {
135+
if err := capiSystem.Run(ctx); err != nil {
136136
return fileList, fmt.Errorf("failed to run cluster api system: %w", err)
137137
}
138138

0 commit comments

Comments
 (0)