Skip to content

Commit 7b84d3c

Browse files
committed
inject ClusterInfo and AddNodesConfig into Ignition asset
1 parent d9354b7 commit 7b84d3c

File tree

4 files changed

+57
-25
lines changed

4 files changed

+57
-25
lines changed

pkg/asset/agent/image/ignition.go

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
agentcommon "github.com/openshift/installer/pkg/asset/agent"
2525
"github.com/openshift/installer/pkg/asset/agent/agentconfig"
2626
"github.com/openshift/installer/pkg/asset/agent/gencrypto"
27+
"github.com/openshift/installer/pkg/asset/agent/joiner"
2728
"github.com/openshift/installer/pkg/asset/agent/manifests"
2829
"github.com/openshift/installer/pkg/asset/agent/mirror"
30+
"github.com/openshift/installer/pkg/asset/agent/workflow"
2931
"github.com/openshift/installer/pkg/asset/ignition"
3032
"github.com/openshift/installer/pkg/asset/ignition/bootstrap"
3133
"github.com/openshift/installer/pkg/asset/password"
@@ -81,6 +83,9 @@ func (a *Ignition) Name() string {
8183
// Dependencies returns the assets on which the Ignition asset depends.
8284
func (a *Ignition) Dependencies() []asset.Asset {
8385
return []asset.Asset{
86+
&workflow.AgentWorkflow{},
87+
&joiner.ClusterInfo{},
88+
&joiner.AddNodesConfig{},
8489
&manifests.AgentManifests{},
8590
&manifests.ExtraManifests{},
8691
&tls.KubeAPIServerLBSignerCertKey{},
@@ -98,12 +103,15 @@ func (a *Ignition) Dependencies() []asset.Asset {
98103

99104
// Generate generates the agent installer ignition.
100105
func (a *Ignition) Generate(dependencies asset.Parents) error {
106+
agentWorkflow := &workflow.AgentWorkflow{}
107+
clusterInfo := &joiner.ClusterInfo{}
108+
addNodesConfig := &joiner.AddNodesConfig{}
101109
agentManifests := &manifests.AgentManifests{}
102110
agentConfigAsset := &agentconfig.AgentConfig{}
103111
agentHostsAsset := &agentconfig.AgentHosts{}
104112
extraManifests := &manifests.ExtraManifests{}
105113
keyPairAsset := &gencrypto.AuthConfig{}
106-
dependencies.Get(agentManifests, agentConfigAsset, agentHostsAsset, extraManifests, keyPairAsset)
114+
dependencies.Get(agentManifests, agentConfigAsset, agentHostsAsset, extraManifests, keyPairAsset, agentWorkflow, clusterInfo, addNodesConfig)
107115

108116
pwd := &password.KubeadminPassword{}
109117
dependencies.Get(pwd)
@@ -128,14 +136,42 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
128136
},
129137
}
130138

131-
nodeZeroIP, err := RetrieveRendezvousIP(agentConfigAsset.Config, agentHostsAsset.Hosts, agentManifests.NMStateConfigs)
132-
if err != nil {
133-
return err
134-
}
139+
clusterName := ""
140+
imageTypeISO := "full-iso"
141+
numMasters := 0
142+
numWorkers := 0
135143

136-
logrus.Infof("The rendezvous host IP (node0 IP) is %s", nodeZeroIP)
144+
switch agentWorkflow.Workflow {
145+
case workflow.AgentWorkflowTypeInstall:
146+
// Set rendezvous IP.
147+
nodeZeroIP, err := RetrieveRendezvousIP(agentConfigAsset.Config, agentHostsAsset.Hosts, agentManifests.NMStateConfigs)
148+
if err != nil {
149+
return err
150+
}
151+
a.RendezvousIP = nodeZeroIP
152+
logrus.Infof("The rendezvous host IP (node0 IP) is %s", a.RendezvousIP)
153+
// Define cluster name and image type.
154+
clusterName = fmt.Sprintf("%s.%s", agentManifests.ClusterDeployment.Spec.ClusterName, agentManifests.ClusterDeployment.Spec.BaseDomain)
155+
if agentManifests.AgentClusterInstall.Spec.PlatformType == hiveext.ExternalPlatformType {
156+
imageTypeISO = "minimal-iso"
157+
}
158+
// Fetch the required number of master and worker nodes.
159+
numMasters = agentManifests.AgentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents
160+
numWorkers = agentManifests.AgentClusterInstall.Spec.ProvisionRequirements.WorkerAgents
161+
162+
case workflow.AgentWorkflowTypeAddNodes:
163+
// In the add-nodes workflow, every node will act independently from the others.
164+
a.RendezvousIP = "127.0.0.1"
165+
// Reuse the existing cluster name.
166+
clusterName = clusterInfo.ClusterName
167+
// Fetch the required number of master and worker nodes.
168+
numMasters = 0
169+
numWorkers = len(addNodesConfig.Config.Hosts)
170+
171+
default:
172+
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
173+
}
137174

138-
a.RendezvousIP = nodeZeroIP
139175
// Default to x86_64
140176
archName := arch.RpmArch(types.ArchitectureAMD64)
141177
if infraEnv.Spec.CpuArchitecture != "" {
@@ -176,16 +212,6 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
176212
}
177213
a.CPUArch = *osImage.CPUArchitecture
178214

179-
clusterName := fmt.Sprintf("%s.%s",
180-
agentManifests.ClusterDeployment.Spec.ClusterName,
181-
agentManifests.ClusterDeployment.Spec.BaseDomain)
182-
183-
imageTypeISO := "full-iso"
184-
platform := agentManifests.AgentClusterInstall.Spec.PlatformType
185-
if platform == hiveext.ExternalPlatformType {
186-
imageTypeISO = "minimal-iso"
187-
}
188-
189215
agentTemplateData := getTemplateData(
190216
clusterName,
191217
agentManifests.GetPullSecretData(),
@@ -194,7 +220,7 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
194220
releaseImageMirror,
195221
len(registriesConfig.MirrorConfig) > 0,
196222
publicContainerRegistries,
197-
agentManifests.AgentClusterInstall,
223+
numMasters, numWorkers,
198224
infraEnvID,
199225
osImage,
200226
infraEnv.Spec.Proxy,
@@ -210,7 +236,7 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
210236

211237
rendezvousHostFile := ignition.FileFromString(rendezvousHostEnvPath,
212238
"root", 0644,
213-
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, nodeZeroIP))
239+
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP))
214240
config.Storage.Files = append(config.Storage.Files, rendezvousHostFile)
215241

216242
err = addBootstrapScripts(&config, agentManifests.ClusterImageSet.Spec.ReleaseImage)
@@ -313,16 +339,16 @@ func addBootstrapScripts(config *igntypes.Config, releaseImage string) (err erro
313339

314340
func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
315341
releaseImageMirror string, haveMirrorConfig bool, publicContainerRegistries string,
316-
agentClusterInstall *hiveext.AgentClusterInstall,
342+
numMasters int, numWorkers int,
317343
infraEnvID string,
318344
osImage *models.OsImage,
319345
proxy *v1beta1.Proxy,
320346
imageTypeISO, privateKey, publicKey string) *agentTemplateData {
321347
return &agentTemplateData{
322348
ServiceProtocol: "http",
323349
PullSecret: pullSecret,
324-
ControlPlaneAgents: agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents,
325-
WorkerAgents: agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents,
350+
ControlPlaneAgents: numMasters,
351+
WorkerAgents: numWorkers,
326352
ReleaseImages: releaseImageList,
327353
ReleaseImage: releaseImage,
328354
ReleaseImageMirror: releaseImageMirror,

pkg/asset/agent/image/ignition_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import (
2222
"github.com/openshift/installer/pkg/asset"
2323
"github.com/openshift/installer/pkg/asset/agent/agentconfig"
2424
"github.com/openshift/installer/pkg/asset/agent/gencrypto"
25+
"github.com/openshift/installer/pkg/asset/agent/joiner"
2526
"github.com/openshift/installer/pkg/asset/agent/manifests"
2627
"github.com/openshift/installer/pkg/asset/agent/mirror"
28+
"github.com/openshift/installer/pkg/asset/agent/workflow"
2729
"github.com/openshift/installer/pkg/asset/password"
2830
"github.com/openshift/installer/pkg/asset/tls"
2931
"github.com/openshift/installer/pkg/types/agent"
@@ -90,7 +92,7 @@ func TestIgnition_getTemplateData(t *testing.T) {
9092
privateKey := "-----BEGIN EC PUBLIC KEY-----\nMFkwEwYHKoAiDHV4tg==\n-----END EC PUBLIC KEY-----\n"
9193
publicKey := "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIOSCfDNmx0qe6dncV4tg==\n-----END EC PRIVATE KEY-----\n"
9294

93-
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, haveMirrorConfig, publicContainerRegistries, agentClusterInstall, infraEnvID, osImage, proxy, "minimal-iso", privateKey, publicKey)
95+
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, haveMirrorConfig, publicContainerRegistries, agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents, agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents, infraEnvID, osImage, proxy, "minimal-iso", privateKey, publicKey)
9496
assert.Equal(t, clusterName, templateData.ClusterName)
9597
assert.Equal(t, "http", templateData.ServiceProtocol)
9698
assert.Equal(t, pullSecret, templateData.PullSecret)
@@ -593,6 +595,9 @@ func buildIgnitionAssetDefaultDependencies(t *testing.T) []asset.Asset {
593595
assert.NoError(t, err)
594596

595597
return []asset.Asset{
598+
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
599+
&joiner.ClusterInfo{},
600+
&joiner.AddNodesConfig{},
596601
&manifests.AgentManifests{
597602
InfraEnv: &aiv1beta1.InfraEnv{
598603
Spec: aiv1beta1.InfraEnvSpec{

pkg/asset/agent/joiner/addnodesconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"os"
77
"path/filepath"
88

9+
"github.com/pkg/errors"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/util/validation/field"
1112
"sigs.k8s.io/yaml"
1213

1314
"github.com/openshift/installer/pkg/asset"
1415
"github.com/openshift/installer/pkg/types/agent"
15-
"github.com/pkg/errors"
1616
)
1717

1818
const (

pkg/asset/agent/joiner/addnodesconfig_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"testing"
55

66
"github.com/golang/mock/gomock"
7+
"github.com/stretchr/testify/assert"
8+
79
"github.com/openshift/installer/pkg/asset"
810
"github.com/openshift/installer/pkg/asset/mock"
9-
"github.com/stretchr/testify/assert"
1011
)
1112

1213
func TestAddNodesConfig_Load(t *testing.T) {

0 commit comments

Comments
 (0)