@@ -53,54 +53,123 @@ func BaremetalHostProvision(
53
53
}
54
54
bmhStatus .IPAddresses ["ctlplane" ] = ctlPlaneIP
55
55
}
56
-
56
+ sts := []util. Template {}
57
57
// Instance UserData/NetworkData overrides the default
58
58
userDataSecret := instance .Spec .BaremetalHosts [hostName ].UserData
59
59
networkDataSecret := instance .Spec .BaremetalHosts [hostName ].NetworkData
60
60
61
+ // User data cloud-init secret from instance or template
61
62
if userDataSecret == nil {
62
63
userDataSecret = instance .Spec .UserData
64
+
65
+ if userDataSecret == nil {
66
+ templateParameters := make (map [string ]interface {})
67
+ templateParameters ["AuthorizedKeys" ] = strings .TrimSuffix (string (sshSecret .Data ["authorized_keys" ]), "\n " )
68
+ templateParameters ["HostName" ] = bmhStatus .Hostname
69
+ //If Hostname is fqdn, use it
70
+ if ! hostNameIsFQDN (bmhStatus .Hostname ) && instance .Spec .DomainName != "" {
71
+ templateParameters ["FQDN" ] = strings .Join ([]string {bmhStatus .Hostname , instance .Spec .DomainName }, "." )
72
+ } else {
73
+ templateParameters ["FQDN" ] = bmhStatus .Hostname
74
+ }
75
+ templateParameters ["CloudUserName" ] = instance .Spec .CloudUserName
76
+
77
+ // Prepare cloudinit (create secret)
78
+ secretLabels := labels .GetLabels (instance , labels .GetGroupLabel (baremetalv1 .ServiceName ), map [string ]string {})
79
+ if passwordSecret != nil && len (passwordSecret .Data ["NodeRootPassword" ]) > 0 {
80
+ templateParameters ["NodeRootPassword" ] = string (passwordSecret .Data ["NodeRootPassword" ])
81
+ }
82
+
83
+ userDataSecretName := fmt .Sprintf (CloudInitUserDataSecretName , instance .Name , bmh )
84
+
85
+ userDataSt := util.Template {
86
+ Name : userDataSecretName ,
87
+ Namespace : instance .Namespace ,
88
+ Type : util .TemplateTypeConfig ,
89
+ InstanceType : instance .Kind ,
90
+ AdditionalTemplate : map [string ]string {"userData" : "/openstackbaremetalset/cloudinit/userdata" },
91
+ Labels : secretLabels ,
92
+ ConfigOptions : templateParameters ,
93
+ }
94
+ sts = append (sts , userDataSt )
95
+ userDataSecret = & corev1.SecretReference {
96
+ Name : userDataSecretName ,
97
+ Namespace : instance .Namespace ,
98
+ }
99
+
100
+ }
63
101
}
64
102
103
+ // Network data secret from instance or template
65
104
if networkDataSecret == nil {
66
105
networkDataSecret = instance .Spec .NetworkData
67
- }
106
+ if instance . Spec . NetworkData == nil {
68
107
69
- sts := []util.Template {}
70
- // User data cloud-init secret
71
- if userDataSecret == nil {
72
- templateParameters := make (map [string ]interface {})
73
- templateParameters ["AuthorizedKeys" ] = strings .TrimSuffix (string (sshSecret .Data ["authorized_keys" ]), "\n " )
74
- templateParameters ["HostName" ] = bmhStatus .Hostname
75
- //If Hostname is fqdn, use it
76
- if ! hostNameIsFQDN (bmhStatus .Hostname ) && instance .Spec .DomainName != "" {
77
- templateParameters ["FQDN" ] = strings .Join ([]string {bmhStatus .Hostname , instance .Spec .DomainName }, "." )
78
- } else {
79
- templateParameters ["FQDN" ] = bmhStatus .Hostname
80
- }
81
- templateParameters ["CloudUserName" ] = instance .Spec .CloudUserName
108
+ // Check IP version and set template variables accordingly
109
+ ipAddr , ipNet , err := net .ParseCIDR (ctlPlaneIP )
110
+ if err != nil {
111
+ // TODO: Remove this conversion once all usage sets ctlPlaneIP in CIDR format.
112
+ ipAddr = net .ParseIP (ctlPlaneIP )
113
+ if ipAddr == nil {
114
+ return err
115
+ }
116
+
117
+ var ipPrefix int
118
+ if ipAddr .To4 () != nil {
119
+ ipPrefix , _ = net .IPMask (net .ParseIP (instance .Spec .CtlplaneNetmask ).To4 ()).Size ()
120
+ } else {
121
+ ipPrefix , _ = net .IPMask (net .ParseIP (instance .Spec .CtlplaneNetmask ).To16 ()).Size ()
122
+ }
123
+ _ , ipNet , err = net .ParseCIDR (fmt .Sprintf ("%s/%d" , ipAddr , ipPrefix ))
124
+ if err != nil {
125
+ return err
126
+ }
127
+ }
82
128
83
- // Prepare cloudinit (create secret)
84
- secretLabels := labels .GetLabels (instance , labels .GetGroupLabel (baremetalv1 .ServiceName ), map [string ]string {})
85
- if passwordSecret != nil && len (passwordSecret .Data ["NodeRootPassword" ]) > 0 {
86
- templateParameters ["NodeRootPassword" ] = string (passwordSecret .Data ["NodeRootPassword" ])
87
- }
129
+ CtlplaneIPVersion := "ipv6"
130
+ if ipAddr .To4 () != nil {
131
+ CtlplaneIPVersion = "ipv4"
132
+ }
88
133
89
- userDataSecretName := fmt .Sprintf (CloudInitUserDataSecretName , instance .Name , bmh )
134
+ templateParameters := make (map [string ]interface {})
135
+ templateParameters ["CtlplaneIpVersion" ] = CtlplaneIPVersion
136
+ templateParameters ["CtlplaneIp" ] = ipAddr
137
+ templateParameters ["CtlplaneInterface" ] = instance .Spec .CtlplaneInterface
138
+ templateParameters ["CtlplaneGateway" ] = instance .Spec .CtlplaneGateway
139
+ templateParameters ["CtlplaneNetmask" ] = net .IP (ipNet .Mask )
140
+ if len (instance .Spec .BootstrapDNS ) > 0 {
141
+ templateParameters ["CtlplaneDns" ] = instance .Spec .BootstrapDNS
142
+ } else {
143
+ templateParameters ["CtlplaneDns" ] = []string {}
144
+ }
90
145
91
- userDataSt := util.Template {
92
- Name : userDataSecretName ,
93
- Namespace : instance .Namespace ,
94
- Type : util .TemplateTypeConfig ,
95
- InstanceType : instance .Kind ,
96
- AdditionalTemplate : map [string ]string {"userData" : "/openstackbaremetalset/cloudinit/userdata" },
97
- Labels : secretLabels ,
98
- ConfigOptions : templateParameters ,
99
- }
100
- sts = append (sts , userDataSt )
101
- userDataSecret = & corev1.SecretReference {
102
- Name : userDataSecretName ,
103
- Namespace : instance .Namespace ,
146
+ if len (instance .Spec .DNSSearchDomains ) > 0 {
147
+ templateParameters ["CtlplaneDnsSearch" ] = instance .Spec .DNSSearchDomains
148
+ } else {
149
+ templateParameters ["CtlplaneDnsSearch" ] = []string {}
150
+ }
151
+
152
+ networkDataSecretName := fmt .Sprintf (CloudInitNetworkDataSecretName , instance .Name , bmh )
153
+
154
+ // Flag the network data secret as safe to collect with must-gather
155
+ secretLabelsWithMustGather := labels .GetLabels (instance , labels .GetGroupLabel (baremetalv1 .ServiceName ), map [string ]string {
156
+ MustGatherSecret : "yes" ,
157
+ })
158
+
159
+ networkDataSt := util.Template {
160
+ Name : networkDataSecretName ,
161
+ Namespace : instance .Namespace ,
162
+ Type : util .TemplateTypeConfig ,
163
+ InstanceType : instance .Kind ,
164
+ AdditionalTemplate : map [string ]string {"networkData" : "/openstackbaremetalset/cloudinit/networkdata" },
165
+ Labels : secretLabelsWithMustGather ,
166
+ ConfigOptions : templateParameters ,
167
+ }
168
+ sts = append (sts , networkDataSt )
169
+ networkDataSecret = & corev1.SecretReference {
170
+ Name : networkDataSecretName ,
171
+ Namespace : instance .Namespace ,
172
+ }
104
173
}
105
174
106
175
}
@@ -119,75 +188,6 @@ func BaremetalHostProvision(
119
188
preProvNetworkData = instance .Spec .BaremetalHosts [hostName ].PreprovisioningNetworkDataName
120
189
}
121
190
122
- if networkDataSecret == nil && preProvNetworkData == "" {
123
-
124
- // Check IP version and set template variables accordingly
125
- ipAddr , ipNet , err := net .ParseCIDR (ctlPlaneIP )
126
- if err != nil {
127
- // TODO: Remove this conversion once all usage sets ctlPlaneIP in CIDR format.
128
- ipAddr = net .ParseIP (ctlPlaneIP )
129
- if ipAddr == nil {
130
- return err
131
- }
132
-
133
- var ipPrefix int
134
- if ipAddr .To4 () != nil {
135
- ipPrefix , _ = net .IPMask (net .ParseIP (instance .Spec .CtlplaneNetmask ).To4 ()).Size ()
136
- } else {
137
- ipPrefix , _ = net .IPMask (net .ParseIP (instance .Spec .CtlplaneNetmask ).To16 ()).Size ()
138
- }
139
- _ , ipNet , err = net .ParseCIDR (fmt .Sprintf ("%s/%d" , ipAddr , ipPrefix ))
140
- if err != nil {
141
- return err
142
- }
143
- }
144
-
145
- CtlplaneIPVersion := "ipv6"
146
- if ipAddr .To4 () != nil {
147
- CtlplaneIPVersion = "ipv4"
148
- }
149
-
150
- templateParameters := make (map [string ]interface {})
151
- templateParameters ["CtlplaneIpVersion" ] = CtlplaneIPVersion
152
- templateParameters ["CtlplaneIp" ] = ipAddr
153
- templateParameters ["CtlplaneInterface" ] = instance .Spec .CtlplaneInterface
154
- templateParameters ["CtlplaneGateway" ] = instance .Spec .CtlplaneGateway
155
- templateParameters ["CtlplaneNetmask" ] = net .IP (ipNet .Mask )
156
- if len (instance .Spec .BootstrapDNS ) > 0 {
157
- templateParameters ["CtlplaneDns" ] = instance .Spec .BootstrapDNS
158
- } else {
159
- templateParameters ["CtlplaneDns" ] = []string {}
160
- }
161
-
162
- if len (instance .Spec .DNSSearchDomains ) > 0 {
163
- templateParameters ["CtlplaneDnsSearch" ] = instance .Spec .DNSSearchDomains
164
- } else {
165
- templateParameters ["CtlplaneDnsSearch" ] = []string {}
166
- }
167
-
168
- networkDataSecretName := fmt .Sprintf (CloudInitNetworkDataSecretName , instance .Name , bmh )
169
-
170
- // Flag the network data secret as safe to collect with must-gather
171
- secretLabelsWithMustGather := labels .GetLabels (instance , labels .GetGroupLabel (baremetalv1 .ServiceName ), map [string ]string {
172
- MustGatherSecret : "yes" ,
173
- })
174
-
175
- networkDataSt := util.Template {
176
- Name : networkDataSecretName ,
177
- Namespace : instance .Namespace ,
178
- Type : util .TemplateTypeConfig ,
179
- InstanceType : instance .Kind ,
180
- AdditionalTemplate : map [string ]string {"networkData" : "/openstackbaremetalset/cloudinit/networkdata" },
181
- Labels : secretLabelsWithMustGather ,
182
- ConfigOptions : templateParameters ,
183
- }
184
- sts = append (sts , networkDataSt )
185
- networkDataSecret = & corev1.SecretReference {
186
- Name : networkDataSecretName ,
187
- Namespace : instance .Namespace ,
188
- }
189
- }
190
-
191
191
if len (sts ) > 0 {
192
192
err := oko_secret .EnsureSecrets (ctx , helper , instance , sts , envVars )
193
193
if err != nil {
0 commit comments