Skip to content

Commit 13c8db4

Browse files
committed
inject ClusterInfo into NMStateConfig asset
1 parent abf1852 commit 13c8db4

File tree

3 files changed

+74
-18
lines changed

3 files changed

+74
-18
lines changed

pkg/asset/agent/manifests/common.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ func getProxy(proxy *types.Proxy) *aiv1beta1.Proxy {
2727
}
2828
}
2929

30-
func getNMStateConfigName(ic *agent.OptionalInstallConfig) string {
31-
return ic.ClusterName()
32-
}
33-
3430
func getNMStateConfigLabels(clusterName string) map[string]string {
3531
return map[string]string{
3632
"infraenvs.agent-install.openshift.io": clusterName,

pkg/asset/agent/manifests/nmstateconfig.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,30 @@ func (n *NMStateConfig) Generate(dependencies asset.Parents) error {
8080
installConfig := &agent.OptionalInstallConfig{}
8181
dependencies.Get(agentHosts, installConfig, agentWorkflow, clusterInfo)
8282

83-
// Not required for the add nodes workflow.
84-
if agentWorkflow.Workflow == workflow.AgentWorkflowTypeAddNodes {
85-
return nil
86-
}
87-
8883
staticNetworkConfig := []*models.HostStaticNetworkConfig{}
8984
nmStateConfigs := []*aiv1beta1.NMStateConfig{}
9085
var data string
9186
var isNetworkConfigAvailable bool
87+
var clusterName, clusterNamespace string
9288

9389
if len(agentHosts.Hosts) == 0 {
9490
return nil
9591
}
96-
if err := validateHostCount(installConfig.Config, agentHosts); err != nil {
97-
return err
92+
93+
switch agentWorkflow.Workflow {
94+
case workflow.AgentWorkflowTypeInstall:
95+
if err := validateHostCount(installConfig.Config, agentHosts); err != nil {
96+
return err
97+
}
98+
clusterName = installConfig.ClusterName()
99+
clusterNamespace = installConfig.ClusterNamespace()
100+
101+
case workflow.AgentWorkflowTypeAddNodes:
102+
clusterName = clusterInfo.ClusterName
103+
clusterNamespace = clusterInfo.Namespace
104+
105+
default:
106+
return fmt.Errorf("AgentWorkflowType value not supported: %s", agentWorkflow.Workflow)
98107
}
99108

100109
for i, host := range agentHosts.Hosts {
@@ -107,9 +116,9 @@ func (n *NMStateConfig) Generate(dependencies asset.Parents) error {
107116
APIVersion: "agent-install.openshift.io/v1beta1",
108117
},
109118
ObjectMeta: metav1.ObjectMeta{
110-
Name: fmt.Sprintf(getNMStateConfigName(installConfig)+"-%d", i),
111-
Namespace: installConfig.ClusterNamespace(),
112-
Labels: getNMStateConfigLabels(installConfig.ClusterName()),
119+
Name: fmt.Sprintf("%s-%d", clusterName, i),
120+
Namespace: clusterNamespace,
121+
Labels: getNMStateConfigLabels(clusterName),
113122
},
114123
Spec: aiv1beta1.NMStateConfigSpec{
115124
NetConfig: aiv1beta1.NetConfig{

pkg/asset/agent/manifests/nmstateconfig_test.go

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
1515
"github.com/openshift/assisted-service/models"
1616
"github.com/openshift/installer/pkg/asset"
17+
agentconfig "github.com/openshift/installer/pkg/asset/agent"
1718
"github.com/openshift/installer/pkg/asset/agent/joiner"
1819
"github.com/openshift/installer/pkg/asset/agent/workflow"
1920
"github.com/openshift/installer/pkg/asset/mock"
@@ -28,6 +29,56 @@ func TestNMStateConfig_Generate(t *testing.T) {
2829
expectedConfig []*aiv1beta1.NMStateConfig
2930
expectedError string
3031
}{
32+
{
33+
name: "add-nodes workflow",
34+
dependencies: []asset.Asset{
35+
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeAddNodes},
36+
&joiner.ClusterInfo{},
37+
getAgentHostsNoHosts(),
38+
&agentconfig.OptionalInstallConfig{},
39+
},
40+
requiresNmstatectl: false,
41+
expectedConfig: nil,
42+
expectedError: "",
43+
},
44+
{
45+
name: "add-nodes workflow - agentHosts with some hosts without networkconfig",
46+
dependencies: []asset.Asset{
47+
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeAddNodes},
48+
&joiner.ClusterInfo{
49+
Namespace: "cluster0",
50+
ClusterName: "ostest",
51+
},
52+
getAgentHostsWithSomeHostsWithoutNetworkConfig(),
53+
&agentconfig.OptionalInstallConfig{},
54+
},
55+
requiresNmstatectl: true,
56+
expectedConfig: []*aiv1beta1.NMStateConfig{
57+
{
58+
TypeMeta: metav1.TypeMeta{
59+
Kind: "NMStateConfig",
60+
APIVersion: "agent-install.openshift.io/v1beta1",
61+
},
62+
ObjectMeta: metav1.ObjectMeta{
63+
Name: "ostest-0",
64+
Namespace: "cluster0",
65+
Labels: getNMStateConfigLabels("ostest"),
66+
},
67+
Spec: aiv1beta1.NMStateConfigSpec{
68+
Interfaces: []*aiv1beta1.Interface{
69+
{
70+
Name: "enp2t0",
71+
MacAddress: "98:af:65:a5:8d:02",
72+
},
73+
},
74+
NetConfig: aiv1beta1.NetConfig{
75+
Raw: unmarshalJSON([]byte(rawNMStateConfigNoIP)),
76+
},
77+
},
78+
},
79+
},
80+
expectedError: "",
81+
},
3182
{
3283
name: "agentHosts does not contain networkConfig",
3384
dependencies: []asset.Asset{
@@ -56,7 +107,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
56107
APIVersion: "agent-install.openshift.io/v1beta1",
57108
},
58109
ObjectMeta: metav1.ObjectMeta{
59-
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-0"),
110+
Name: fmt.Sprint(getValidOptionalInstallConfig().ClusterName(), "-0"),
60111
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
61112
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig().ClusterName()),
62113
},
@@ -91,7 +142,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
91142
APIVersion: "agent-install.openshift.io/v1beta1",
92143
},
93144
ObjectMeta: metav1.ObjectMeta{
94-
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-0"),
145+
Name: fmt.Sprint(getValidOptionalInstallConfig().ClusterName(), "-0"),
95146
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
96147
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig().ClusterName()),
97148
},
@@ -117,7 +168,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
117168
APIVersion: "agent-install.openshift.io/v1beta1",
118169
},
119170
ObjectMeta: metav1.ObjectMeta{
120-
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-1"),
171+
Name: fmt.Sprint(getValidOptionalInstallConfig().ClusterName(), "-1"),
121172
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
122173
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig().ClusterName()),
123174
},
@@ -139,7 +190,7 @@ func TestNMStateConfig_Generate(t *testing.T) {
139190
APIVersion: "agent-install.openshift.io/v1beta1",
140191
},
141192
ObjectMeta: metav1.ObjectMeta{
142-
Name: fmt.Sprint(getNMStateConfigName(getValidOptionalInstallConfig()), "-2"),
193+
Name: fmt.Sprint(getValidOptionalInstallConfig().ClusterName(), "-2"),
143194
Namespace: getValidOptionalInstallConfig().ClusterNamespace(),
144195
Labels: getNMStateConfigLabels(getValidOptionalInstallConfig().ClusterName()),
145196
},

0 commit comments

Comments
 (0)