Skip to content

Commit 3f030bd

Browse files
Merge pull request openshift#8080 from andfasano/agent-day2-addnodesconfig
AGENT-874: use AddNodesConfig asset
2 parents bc9836a + 7b84d3c commit 3f030bd

File tree

7 files changed

+257
-59
lines changed

7 files changed

+257
-59
lines changed

pkg/asset/agent/agentconfig/agenthosts.go

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
1414
"github.com/openshift/installer/pkg/asset"
1515
agentAsset "github.com/openshift/installer/pkg/asset/agent"
16+
"github.com/openshift/installer/pkg/asset/agent/joiner"
1617
"github.com/openshift/installer/pkg/asset/agent/workflow"
1718
"github.com/openshift/installer/pkg/types/agent"
1819
"github.com/openshift/installer/pkg/types/baremetal/validation"
@@ -39,7 +40,7 @@ type nmStateInterface struct {
3940
// OptionalInstallConfig assets.
4041
type AgentHosts struct {
4142
Hosts []agent.Host
42-
RendezvousIP string
43+
rendezvousIP string
4344
}
4445

4546
// Name returns a human friendly name.
@@ -51,6 +52,7 @@ func (a *AgentHosts) Name() string {
5152
func (a *AgentHosts) Dependencies() []asset.Asset {
5253
return []asset.Asset{
5354
&workflow.AgentWorkflow{},
55+
&joiner.AddNodesConfig{},
5456
&agentAsset.OptionalInstallConfig{},
5557
&AgentConfig{},
5658
}
@@ -59,37 +61,41 @@ func (a *AgentHosts) Dependencies() []asset.Asset {
5961
// Generate generates the Hosts data.
6062
func (a *AgentHosts) Generate(dependencies asset.Parents) error {
6163
agentWorkflow := &workflow.AgentWorkflow{}
64+
addNodesConfig := &joiner.AddNodesConfig{}
6265
agentConfig := &AgentConfig{}
6366
installConfig := &agentAsset.OptionalInstallConfig{}
64-
dependencies.Get(agentConfig, installConfig, agentWorkflow)
65-
66-
// Temporary skip in case of add nodes workflow. To be addressed
67-
// by AGENT-874
68-
if agentWorkflow.Workflow == workflow.AgentWorkflowTypeAddNodes {
69-
return nil
70-
}
71-
72-
if agentConfig.Config != nil {
73-
a.RendezvousIP = agentConfig.Config.RendezvousIP
74-
a.Hosts = append(a.Hosts, agentConfig.Config.Hosts...)
75-
if len(a.Hosts) > 0 {
76-
// Hosts defined in agent-config take precedence
77-
logrus.Debugf("Using hosts from %s", agentConfigFilename)
67+
dependencies.Get(agentConfig, installConfig, agentWorkflow, addNodesConfig)
68+
69+
switch agentWorkflow.Workflow {
70+
case workflow.AgentWorkflowTypeInstall:
71+
if agentConfig.Config != nil {
72+
a.rendezvousIP = agentConfig.Config.RendezvousIP
73+
a.Hosts = append(a.Hosts, agentConfig.Config.Hosts...)
74+
if len(a.Hosts) > 0 {
75+
// Hosts defined in agent-config take precedence
76+
logrus.Debugf("Using hosts from %s", agentConfigFilename)
77+
}
7878
}
79-
}
8079

81-
if installConfig != nil && installConfig.GetBaremetalHosts() != nil {
82-
// Only use hosts from install-config if they are not defined in agent-config
83-
if len(a.Hosts) == 0 {
84-
if err := a.getInstallConfigDefaults(installConfig); err != nil {
85-
return errors.Wrapf(err, "invalid host definition in %s", agentAsset.InstallConfigFilename)
80+
if installConfig != nil && installConfig.GetBaremetalHosts() != nil {
81+
// Only use hosts from install-config if they are not defined in agent-config
82+
if len(a.Hosts) == 0 {
83+
if err := a.getInstallConfigDefaults(installConfig); err != nil {
84+
return errors.Wrapf(err, "invalid host definition in %s", agentAsset.InstallConfigFilename)
85+
}
86+
} else {
87+
logrus.Warnf(fmt.Sprintf("hosts from %s are ignored", agentAsset.InstallConfigFilename))
8688
}
87-
} else {
88-
logrus.Warnf(fmt.Sprintf("hosts from %s are ignored", agentAsset.InstallConfigFilename))
8989
}
90+
91+
case workflow.AgentWorkflowTypeAddNodes:
92+
a.Hosts = append(a.Hosts, addNodesConfig.Config.Hosts...)
93+
94+
default:
95+
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
9096
}
9197

92-
if err := a.validateAgentHosts(installConfig).ToAggregate(); err != nil {
98+
if err := a.validateAgentHosts().ToAggregate(); err != nil {
9399
return errors.Wrapf(err, "invalid Hosts configuration")
94100
}
95101

@@ -106,7 +112,7 @@ func (a *AgentHosts) Load(f asset.FileFetcher) (bool, error) {
106112
return false, nil
107113
}
108114

109-
func (a *AgentHosts) validateAgentHosts(installConfig *agentAsset.OptionalInstallConfig) field.ErrorList {
115+
func (a *AgentHosts) validateAgentHosts() field.ErrorList {
110116
allErrs := field.ErrorList{}
111117

112118
macs := make(map[string]bool)
@@ -126,7 +132,7 @@ func (a *AgentHosts) validateAgentHosts(installConfig *agentAsset.OptionalInstal
126132
}
127133
}
128134

129-
if err := a.validateRendezvousIPNotWorker(a.RendezvousIP, a.Hosts); err != nil {
135+
if err := a.validateRendezvousIPNotWorker(a.rendezvousIP, a.Hosts); err != nil {
130136
allErrs = append(allErrs, err...)
131137
}
132138

pkg/asset/agent/agentconfig/agenthosts_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
1313
"github.com/openshift/installer/pkg/asset"
1414
agentAsset "github.com/openshift/installer/pkg/asset/agent"
15+
"github.com/openshift/installer/pkg/asset/agent/joiner"
1516
"github.com/openshift/installer/pkg/asset/agent/workflow"
1617
"github.com/openshift/installer/pkg/asset/installconfig"
1718
"github.com/openshift/installer/pkg/ipnet"
@@ -78,10 +79,36 @@ func TestAgentHosts_Generate(t *testing.T) {
7879
expectedError string
7980
expectedConfig *AgentHostsBuilder
8081
}{
82+
{
83+
name: "host-from-add-nodes-config",
84+
dependencies: []asset.Asset{
85+
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeAddNodes},
86+
&joiner.AddNodesConfig{
87+
Config: joiner.Config{
88+
Hosts: []agent.Host{
89+
{
90+
Hostname: "extra-worker-0",
91+
Role: "worker",
92+
Interfaces: []*aiv1beta1.Interface{
93+
{
94+
Name: "enp3s1",
95+
MacAddress: "28:d2:44:d2:b2:1a",
96+
},
97+
},
98+
},
99+
},
100+
},
101+
},
102+
getNoHostsInstallConfig(),
103+
getNoHostsAgentConfig(),
104+
},
105+
expectedConfig: agentHosts().hosts(agentHost().name("extra-worker-0").role("worker").interfaces(iface("enp3s1", "28:d2:44:d2:b2:1a"))),
106+
},
81107
{
82108
name: "no-hosts",
83109
dependencies: []asset.Asset{
84110
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
111+
&joiner.AddNodesConfig{},
85112
getNoHostsInstallConfig(),
86113
getNoHostsAgentConfig(),
87114
},
@@ -91,6 +118,7 @@ func TestAgentHosts_Generate(t *testing.T) {
91118
name: "host-from-agent-config",
92119
dependencies: []asset.Asset{
93120
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
121+
&joiner.AddNodesConfig{},
94122
getInstallConfigSingleHost(),
95123
getAgentConfigSingleHost(),
96124
},
@@ -100,6 +128,7 @@ func TestAgentHosts_Generate(t *testing.T) {
100128
name: "host-from-install-config",
101129
dependencies: []asset.Asset{
102130
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
131+
&joiner.AddNodesConfig{},
103132
getInstallConfigSingleHost(),
104133
getNoHostsAgentConfig(),
105134
},
@@ -109,6 +138,7 @@ func TestAgentHosts_Generate(t *testing.T) {
109138
name: "multi-host-from-agent-config",
110139
dependencies: []asset.Asset{
111140
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
141+
&joiner.AddNodesConfig{},
112142
getInstallConfigSingleHost(),
113143
getAgentConfigMultiHost(),
114144
},
@@ -120,6 +150,7 @@ func TestAgentHosts_Generate(t *testing.T) {
120150
name: "multi-host-from-install-config",
121151
dependencies: []asset.Asset{
122152
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
153+
&joiner.AddNodesConfig{},
123154
getInstallConfigMultiHost(),
124155
getNoHostsAgentConfig(),
125156
},
@@ -131,6 +162,7 @@ func TestAgentHosts_Generate(t *testing.T) {
131162
name: "unsupported-device-name-agent-config",
132163
dependencies: []asset.Asset{
133164
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
165+
&joiner.AddNodesConfig{},
134166
getInstallConfigSingleHost(),
135167
getAgentConfigUnsupportedDeviceName(),
136168
},
@@ -141,6 +173,7 @@ func TestAgentHosts_Generate(t *testing.T) {
141173
name: "unsupported-wwn-extension-install-config",
142174
dependencies: []asset.Asset{
143175
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
176+
&joiner.AddNodesConfig{},
144177
getInstallConfigUnsupportedWWNExtension(),
145178
getNoHostsAgentConfig(),
146179
},
@@ -151,6 +184,7 @@ func TestAgentHosts_Generate(t *testing.T) {
151184
name: "unsupported-www-vendor-extension-agent-config",
152185
dependencies: []asset.Asset{
153186
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
187+
&joiner.AddNodesConfig{},
154188
getInstallConfigSingleHost(),
155189
getAgentConfigUnsupportedWWNVendorExtension(),
156190
},
@@ -161,6 +195,7 @@ func TestAgentHosts_Generate(t *testing.T) {
161195
name: "node-hostname-and-role-are-not-required",
162196
dependencies: []asset.Asset{
163197
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
198+
&joiner.AddNodesConfig{},
164199
getInstallConfigNoHostnameOrRole(),
165200
getNoHostsAgentConfig(),
166201
},
@@ -170,6 +205,7 @@ func TestAgentHosts_Generate(t *testing.T) {
170205
name: "host-roles-have-incorrect-values",
171206
dependencies: []asset.Asset{
172207
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
208+
&joiner.AddNodesConfig{},
173209
getInstallConfigSingleHost(),
174210
getAgentConfigInvalidHostRole(),
175211
},
@@ -180,6 +216,7 @@ func TestAgentHosts_Generate(t *testing.T) {
180216
name: "different-hosts-cannot-have-same-mac",
181217
dependencies: []asset.Asset{
182218
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
219+
&joiner.AddNodesConfig{},
183220
getInstallConfigSameMac(),
184221
getNoHostsAgentConfig(),
185222
},
@@ -190,6 +227,7 @@ func TestAgentHosts_Generate(t *testing.T) {
190227
name: "invalid-mac",
191228
dependencies: []asset.Asset{
192229
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
230+
&joiner.AddNodesConfig{},
193231
getInstallConfigSingleHost(),
194232
getAgentConfigInvalidMac(),
195233
},
@@ -200,6 +238,7 @@ func TestAgentHosts_Generate(t *testing.T) {
200238
name: "duplicate-mac-same-host-agent-config",
201239
dependencies: []asset.Asset{
202240
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
241+
&joiner.AddNodesConfig{},
203242
getInstallConfigSingleHost(),
204243
getAgentConfigInvalidInterfaces(),
205244
},
@@ -210,6 +249,7 @@ func TestAgentHosts_Generate(t *testing.T) {
210249
name: "duplicate-mac-same-host-install-config",
211250
dependencies: []asset.Asset{
212251
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
252+
&joiner.AddNodesConfig{},
213253
getInstallConfigInvalidInterfaces(),
214254
getNoHostsAgentConfig(),
215255
},
@@ -220,6 +260,7 @@ func TestAgentHosts_Generate(t *testing.T) {
220260
name: "invalid-rendezvous-agent-config",
221261
dependencies: []asset.Asset{
222262
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
263+
&joiner.AddNodesConfig{},
223264
getInstallConfigSingleHost(),
224265
getAgentConfigInvalidRendezvousIP(),
225266
},
@@ -230,6 +271,7 @@ func TestAgentHosts_Generate(t *testing.T) {
230271
name: "invalid-rendezvous-install-config",
231272
dependencies: []asset.Asset{
232273
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
274+
&joiner.AddNodesConfig{},
233275
getInstallConfigInvalidRendezvousIP(),
234276
getNoHostsAgentConfig(),
235277
},
@@ -240,6 +282,7 @@ func TestAgentHosts_Generate(t *testing.T) {
240282
name: "host-missing-interface-error",
241283
dependencies: []asset.Asset{
242284
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
285+
&joiner.AddNodesConfig{},
243286
getInstallConfigSingleHost(),
244287
getAgentConfigMissingInterfaces(),
245288
},
@@ -261,6 +304,8 @@ func TestAgentHosts_Generate(t *testing.T) {
261304
assert.NoError(t, err)
262305
if tc.expectedConfig != nil {
263306
assert.Equal(t, tc.expectedConfig.build().Hosts, asset.Hosts, "unexpected Config in AgentHosts")
307+
} else {
308+
assert.Nil(t, asset.Hosts)
264309
}
265310
}
266311
})

0 commit comments

Comments
 (0)