Skip to content

Commit 2063903

Browse files
committed
feat: add arch logic to injector pod
1 parent c03efd6 commit 2063903

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/pkg/cluster/injector.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
)
3636

3737
// StartInjection initializes a Zarf injection into the cluster.
38-
func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string) error {
38+
func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, architecture string, injectorSeedSrcs []string) error {
3939
l := logger.From(ctx)
4040
start := time.Now()
4141
// Stop any previous running injection before starting.
@@ -93,7 +93,7 @@ func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string,
9393
// TODO: Remove use of passing data through global variables.
9494
config.ZarfSeedPort = fmt.Sprintf("%d", svc.Spec.Ports[0].NodePort)
9595

96-
pod := buildInjectionPod(injectorNodeName, injectorImage, payloadCmNames, shasum, resReq)
96+
pod := buildInjectionPod(injectorNodeName, injectorImage, payloadCmNames, shasum, resReq, architecture)
9797
_, err = c.Clientset.CoreV1().Pods(*pod.Namespace).Apply(ctx, pod, metav1.ApplyOptions{Force: true, FieldManager: FieldManagerName})
9898
if err != nil {
9999
return fmt.Errorf("error creating pod in cluster: %w", err)
@@ -308,7 +308,7 @@ func hasBlockingTaints(taints []corev1.Taint) bool {
308308
return false
309309
}
310310

311-
func buildInjectionPod(nodeName, image string, payloadCmNames []string, shasum string, resReq *v1ac.ResourceRequirementsApplyConfiguration) *v1ac.PodApplyConfiguration {
311+
func buildInjectionPod(nodeName, image string, payloadCmNames []string, shasum string, resReq *v1ac.ResourceRequirementsApplyConfiguration, architecture string) *v1ac.PodApplyConfiguration {
312312
executeMode := int32(0777)
313313
userID := int64(1000)
314314
groupID := int64(2000)
@@ -367,6 +367,9 @@ func buildInjectionPod(nodeName, image string, payloadCmNames []string, shasum s
367367
WithType(corev1.SeccompProfileTypeRuntimeDefault),
368368
),
369369
).
370+
WithNodeSelector(map[string]string{
371+
"kubernetes.io/arch": architecture,
372+
}).
370373
WithContainers(
371374
v1ac.Container().
372375
WithName("injector").

src/pkg/cluster/injector_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestInjector(t *testing.T) {
107107
_, err = layout.Write(filepath.Join(tmpDir, "seed-images"), idx)
108108
require.NoError(t, err)
109109

110-
err = c.StartInjection(ctx, tmpDir, t.TempDir(), nil)
110+
err = c.StartInjection(ctx, tmpDir, t.TempDir(), "amd64", nil)
111111
require.NoError(t, err)
112112

113113
podList, err := cs.CoreV1().Pods(state.ZarfNamespaceName).List(ctx, metav1.ListOptions{})
@@ -163,7 +163,7 @@ func TestBuildInjectionPod(t *testing.T) {
163163
corev1.ResourceCPU: resource.MustParse("1"),
164164
corev1.ResourceMemory: resource.MustParse("256Mi"),
165165
})
166-
pod := buildInjectionPod("injection-node", "docker.io/library/ubuntu:latest", []string{"foo", "bar"}, "shasum", resReq)
166+
pod := buildInjectionPod("injection-node", "docker.io/library/ubuntu:latest", []string{"foo", "bar"}, "shasum", resReq, "amd64")
167167
require.Equal(t, "injector", *pod.Name)
168168
b, err := json.MarshalIndent(pod, "", " ")
169169
require.NoError(t, err)

src/pkg/cluster/testdata/expected-injection-pod.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
}
9999
],
100100
"restartPolicy": "Never",
101+
"nodeSelector": {
102+
"kubernetes.io/arch": "amd64"
103+
},
101104
"nodeName": "injection-node",
102105
"securityContext": {
103106
"runAsUser": 1000,

src/pkg/packager/deploy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type deployer struct {
7272
// Deploy takes a reference to a `layout.PackageLayout` and deploys the package. If successful, returns a list of components that were successfully deployed.
7373
func Deploy(ctx context.Context, pkgLayout *layout.PackageLayout, opts DeployOptions) ([]types.DeployedComponent, error) {
7474
l := logger.From(ctx)
75-
l.Info("starting deploy", "package", pkgLayout.Pkg.Metadata.Name)
75+
l.Info("starting deploy", "package", pkgLayout.Pkg.Metadata.Name, "architecture", pkgLayout.Pkg.Metadata.Architecture)
7676
start := time.Now()
7777

7878
if opts.Retries == 0 {
@@ -261,7 +261,7 @@ func (d *deployer) deployInitComponent(ctx context.Context, pkgLayout *layout.Pa
261261

262262
// Before deploying the seed registry, start the injector
263263
if isSeedRegistry {
264-
err := d.c.StartInjection(ctx, pkgLayout.DirPath(), pkgLayout.GetImageDirPath(), component.Images)
264+
err := d.c.StartInjection(ctx, pkgLayout.DirPath(), pkgLayout.GetImageDirPath(), pkgLayout.Pkg.Metadata.Architecture, component.Images)
265265
if err != nil {
266266
return nil, err
267267
}

0 commit comments

Comments
 (0)