Skip to content

Commit 01b922e

Browse files
Merge pull request openshift#8644 from rwsu/AGENT-910
AGENT-910: node-joiner multi-arch support
2 parents 658942c + 481e2dc commit 01b922e

File tree

3 files changed

+149
-10
lines changed

3 files changed

+149
-10
lines changed

pkg/asset/agent/joiner/addnodesconfig.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ type Config struct {
3636
metav1.TypeMeta `json:",inline"`
3737
metav1.ObjectMeta `json:"metadata,omitempty"`
3838

39-
Hosts []agent.Host `json:"hosts,omitempty"`
39+
CPUArchitecture string `json:"cpuArchitecture,omitempty"`
40+
Hosts []agent.Host `json:"hosts,omitempty"`
4041
}
4142

4243
// Params is used to store the command line parameters.

pkg/asset/agent/joiner/clusterinfo.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
1010
"github.com/coreos/stream-metadata-go/arch"
1111
"github.com/coreos/stream-metadata-go/stream"
12+
"github.com/sirupsen/logrus"
1213
"k8s.io/apimachinery/pkg/api/errors"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/client-go/kubernetes"
@@ -98,10 +99,12 @@ func (ci *ClusterInfo) Generate(_ context.Context, dependencies asset.Parents) e
9899
if err != nil {
99100
return err
100101
}
101-
err = ci.retrieveArchitecture()
102+
103+
err = ci.retrieveArchitecture(addNodesConfig)
102104
if err != nil {
103105
return err
104106
}
107+
105108
err = ci.retrieveInstallConfigData()
106109
if err != nil {
107110
return err
@@ -200,14 +203,19 @@ func (ci *ClusterInfo) retrieveUserTrustBundle() error {
200203
return nil
201204
}
202205

203-
func (ci *ClusterInfo) retrieveArchitecture() error {
204-
nodes, err := ci.Client.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
205-
LabelSelector: "node-role.kubernetes.io/master",
206-
})
207-
if err != nil {
208-
return err
206+
func (ci *ClusterInfo) retrieveArchitecture(addNodesConfig *AddNodesConfig) error {
207+
if addNodesConfig.Config.CPUArchitecture != "" {
208+
logrus.Infof("CPU architecture set to: %v", addNodesConfig.Config.CPUArchitecture)
209+
ci.Architecture = addNodesConfig.Config.CPUArchitecture
210+
} else {
211+
nodes, err := ci.Client.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
212+
LabelSelector: "node-role.kubernetes.io/master",
213+
})
214+
if err != nil {
215+
return err
216+
}
217+
ci.Architecture = nodes.Items[0].Status.NodeInfo.Architecture
209218
}
210-
ci.Architecture = nodes.Items[0].Status.NodeInfo.Architecture
211219

212220
return nil
213221
}

pkg/asset/agent/joiner/clusterinfo_test.go

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestClusterInfo_Generate(t *testing.T) {
2828
cases := []struct {
2929
name string
3030
workflow workflow.AgentWorkflowType
31+
nodesConfig AddNodesConfig
3132
objects []runtime.Object
3233
openshiftObjects []runtime.Object
3334
expectedClusterInfo ClusterInfo
@@ -162,11 +163,126 @@ func TestClusterInfo_Generate(t *testing.T) {
162163
},
163164
},
164165
},
166+
{
167+
name: "architecture specified in nodesConfig as arm64 and target cluster is amd64",
168+
workflow: workflow.AgentWorkflowTypeAddNodes,
169+
nodesConfig: AddNodesConfig{
170+
Config: Config{
171+
CPUArchitecture: "arm64",
172+
},
173+
},
174+
openshiftObjects: []runtime.Object{
175+
&configv1.ClusterVersion{
176+
ObjectMeta: v1.ObjectMeta{
177+
Name: "version",
178+
},
179+
Spec: configv1.ClusterVersionSpec{
180+
ClusterID: "1b5ba46b-7e56-47b1-a326-a9eebddfb38c",
181+
},
182+
Status: configv1.ClusterVersionStatus{
183+
History: []configv1.UpdateHistory{
184+
{
185+
Image: "registry.ci.openshift.org/ocp/release@sha256:65d9b652d0d23084bc45cb66001c22e796d43f5e9e005c2bc2702f94397d596e",
186+
Version: "4.15.0",
187+
},
188+
},
189+
},
190+
},
191+
&configv1.Proxy{
192+
ObjectMeta: v1.ObjectMeta{
193+
Name: "cluster",
194+
},
195+
Spec: configv1.ProxySpec{
196+
HTTPProxy: "http://proxy",
197+
HTTPSProxy: "https://proxy",
198+
NoProxy: "localhost",
199+
},
200+
},
201+
},
202+
objects: []runtime.Object{
203+
&corev1.Secret{
204+
ObjectMeta: v1.ObjectMeta{
205+
Name: "pull-secret",
206+
Namespace: "openshift-config",
207+
},
208+
Data: map[string][]byte{
209+
".dockerconfigjson": []byte("c3VwZXJzZWNyZXQK"),
210+
},
211+
},
212+
&corev1.ConfigMap{
213+
ObjectMeta: v1.ObjectMeta{
214+
Name: "user-ca-bundle",
215+
Namespace: "openshift-config",
216+
},
217+
Data: map[string]string{
218+
"ca-bundle.crt": "--- bundle ---",
219+
},
220+
},
221+
&corev1.Node{
222+
ObjectMeta: v1.ObjectMeta{
223+
Labels: map[string]string{
224+
"node-role.kubernetes.io/master": "",
225+
},
226+
},
227+
Status: corev1.NodeStatus{
228+
NodeInfo: corev1.NodeSystemInfo{
229+
Architecture: "amd64",
230+
},
231+
},
232+
},
233+
&corev1.ConfigMap{
234+
ObjectMeta: v1.ObjectMeta{
235+
Name: "cluster-config-v1",
236+
Namespace: "kube-system",
237+
},
238+
Data: map[string]string{
239+
"install-config": makeInstallConfig(t),
240+
},
241+
},
242+
&corev1.ConfigMap{
243+
ObjectMeta: v1.ObjectMeta{
244+
Name: "coreos-bootimages",
245+
Namespace: "openshift-machine-config-operator",
246+
},
247+
Data: map[string]string{
248+
"stream": makeCoreOsBootImages(t, buildStreamData()),
249+
},
250+
},
251+
},
252+
expectedClusterInfo: ClusterInfo{
253+
ClusterID: "1b5ba46b-7e56-47b1-a326-a9eebddfb38c",
254+
ClusterName: "ostest",
255+
ReleaseImage: "registry.ci.openshift.org/ocp/release@sha256:65d9b652d0d23084bc45cb66001c22e796d43f5e9e005c2bc2702f94397d596e",
256+
Version: "4.15.0",
257+
APIDNSName: "api.ostest.test.metalkube.org",
258+
Namespace: "cluster0",
259+
PullSecret: "c3VwZXJzZWNyZXQK",
260+
UserCaBundle: "--- bundle ---",
261+
Architecture: "arm64",
262+
Proxy: &types.Proxy{
263+
HTTPProxy: "http://proxy",
264+
HTTPSProxy: "https://proxy",
265+
NoProxy: "localhost",
266+
},
267+
ImageDigestSources: []types.ImageDigestSource{
268+
{
269+
Source: "quay.io/openshift-release-dev/ocp-v4.0-art-dev",
270+
Mirrors: []string{
271+
"registry.example.com:5000/ocp4/openshift4",
272+
},
273+
},
274+
},
275+
PlatformType: v1beta1.BareMetalPlatformType,
276+
SSHKey: "my-ssh-key",
277+
OSImage: buildStreamData(),
278+
OSImageLocation: "http://my-coreosimage-url/416.94.202402130130-1",
279+
},
280+
},
165281
}
166282
for _, tc := range cases {
167283
t.Run(tc.name, func(t *testing.T) {
168284
agentWorkflow := &workflow.AgentWorkflow{Workflow: tc.workflow}
169-
addNodesConfig := &AddNodesConfig{}
285+
addNodesConfig := &tc.nodesConfig
170286
parents := asset.Parents{}
171287
parents.Add(agentWorkflow)
172288
parents.Add(addNodesConfig)
@@ -219,6 +335,20 @@ func buildStreamData() *stream.Stream {
219335
},
220336
},
221337
},
338+
"aarch64": {
339+
Artifacts: map[string]stream.PlatformArtifacts{
340+
"metal": {
341+
Release: "416.94.202402130130-0",
342+
Formats: map[string]stream.ImageFormat{
343+
"iso": {
344+
Disk: &stream.Artifact{
345+
Location: "http://my-coreosimage-url/416.94.202402130130-1",
346+
},
347+
},
348+
},
349+
},
350+
},
351+
},
222352
},
223353
}
224354
}

0 commit comments

Comments
 (0)