Skip to content

Commit 4b37fa5

Browse files
committed
feat: add zarf variable for what arch the package was built against
Signed-off-by: Allen Conlon <[email protected]>
1 parent d3dd002 commit 4b37fa5

File tree

10 files changed

+37
-7
lines changed

10 files changed

+37
-7
lines changed

packages/gitea/gitea-values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ persistence:
88

99
replicaCount: ###ZARF_VAR_GIT_SERVER_REPLICA_COUNT###
1010

11+
nodeSelector:
12+
kubernetes.io/arch: "###ZARF_ARCHITECTURE###"
13+
1114
gitea:
1215
admin:
1316
username: "###ZARF_GIT_PUSH###"

packages/zarf-agent/manifests/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ spec:
1717
# Don't mutate this pod, that would be sad times
1818
zarf.dev/agent: ignore
1919
spec:
20+
nodeSelector:
21+
kubernetes.io/arch: "###ZARF_ARCHITECTURE###"
2022
imagePullSecrets:
2123
- name: private-registry
2224
priorityClassName: system-node-critical

packages/zarf-registry/chart/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ spec:
2626
annotations:
2727
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
2828
spec:
29+
{{- with .Values.nodeSelector }}
30+
nodeSelector:
31+
{{ toYaml . | indent 8 }}
32+
{{- end }}
2933
serviceAccountName: {{ include "docker-registry.serviceAccountName" . }}
3034
{{- if .Values.imagePullSecrets }}
3135
imagePullSecrets:

packages/zarf-registry/chart/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ serviceAccount:
8787
create: false
8888
name: ""
8989
annotations: {}
90+
91+
nodeSelector: {}

packages/zarf-registry/registry-values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ serviceAccount:
6262
name: "###ZARF_VAR_REGISTRY_SERVICE_ACCOUNT_NAME###"
6363
annotations:
6464
###ZARF_VAR_REGISTRY_SERVICE_ACCOUNT_ANNOTATIONS###
65+
66+
nodeSelector:
67+
kubernetes.io/arch: "###ZARF_ARCHITECTURE###"

src/internal/packager/template/template_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ func TestGetSanitizedTemplateMap(t *testing.T) {
4444
"###ZARF_GIT_AUTH_PUSH###": {Sensitive: true, Value: "secret2"},
4545
"###ZARF_GIT_PUSH###": {Sensitive: false, Value: "zarf-git-user"},
4646
"###ZARF_GIT_PULL###": {Sensitive: false, Value: "zarf-git-read-user"},
47+
"###ZARF_ARCHITECTURE###": {Sensitive: false, Value: "amd64"},
4748
},
4849
expected: map[string]string{
4950
"###ZARF_GIT_AUTH_PULL###": "**sanitized**",
5051
"###ZARF_GIT_AUTH_PUSH###": "**sanitized**",
5152
"###ZARF_GIT_PULL###": "zarf-git-read-user",
5253
"###ZARF_GIT_PUSH###": "zarf-git-user",
54+
"###ZARF_ARCHITECTURE###": "amd64",
5355
},
5456
},
5557
{

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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type deployer struct {
7373
// Deploy takes a reference to a `layout.PackageLayout` and deploys the package. If successful, returns a list of components that were successfully deployed.
7474
func Deploy(ctx context.Context, pkgLayout *layout.PackageLayout, opts DeployOptions) ([]state.DeployedComponent, error) {
7575
l := logger.From(ctx)
76-
l.Info("starting deploy", "package", pkgLayout.Pkg.Metadata.Name)
76+
l.Info("starting deploy", "package", pkgLayout.Pkg.Metadata.Name, "architecture", pkgLayout.Pkg.Metadata.Architecture)
7777
start := time.Now()
7878
if opts.NamespaceOverride != "" {
7979
if err := OverridePackageNamespace(pkgLayout.Pkg, opts.NamespaceOverride); err != nil {
@@ -267,7 +267,7 @@ func (d *deployer) deployInitComponent(ctx context.Context, pkgLayout *layout.Pa
267267

268268
// Before deploying the seed registry, start the injector
269269
if isSeedRegistry {
270-
err := d.c.StartInjection(ctx, pkgLayout.DirPath(), pkgLayout.GetImageDirPath(), component.Images)
270+
err := d.c.StartInjection(ctx, pkgLayout.DirPath(), pkgLayout.GetImageDirPath(), pkgLayout.Pkg.Metadata.Architecture, component.Images)
271271
if err != nil {
272272
return nil, err
273273
}
@@ -329,6 +329,13 @@ func (d *deployer) deployComponent(ctx context.Context, pkgLayout *layout.Packag
329329
}
330330

331331
applicationTemplates, err := template.GetZarfTemplates(ctx, component.Name, d.s)
332+
333+
// This variable needs to be set from the package metadata architecture
334+
// This might be able to be expanded to include all the .metadata settings
335+
applicationTemplates["###ZARF_ARCHITECTURE###"] = &variables.TextTemplate{
336+
Value: pkgLayout.Pkg.Metadata.Architecture,
337+
}
338+
332339
if err != nil {
333340
return nil, err
334341
}
@@ -595,6 +602,7 @@ func setupState(ctx context.Context, c *cluster.Cluster, pkg v1alpha1.ZarfPackag
595602
if s == nil {
596603
return nil, errors.New("cluster state should not be nil")
597604
}
605+
s.Architecture = pkg.Metadata.Architecture
598606
if pkg.Metadata.YOLO && s.Distro != "YOLO" {
599607
l.Warn("This package is in YOLO mode, but the cluster was already initialized with 'zarf init'. " +
600608
"This may cause issues if the package does not exclude any charts or manifests from the Zarf Agent using " +

0 commit comments

Comments
 (0)