Skip to content

Commit

Permalink
refactor: normal creator
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Laine <[email protected]>
  • Loading branch information
phillebaba committed Oct 18, 2024
1 parent 56e48d4 commit 6879878
Show file tree
Hide file tree
Showing 40 changed files with 3,198 additions and 217 deletions.
2 changes: 1 addition & 1 deletion examples/manifests/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ components:
kustomizations:
# kustomizations can be specified relative to the `zarf.yaml` or as remoteBuild resources with the
# following syntax: https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md:
- github.com/stefanprodan/podinfo//kustomize?ref=6.4.0
- https://github.com/stefanprodan/podinfo//kustomize?ref=6.4.0
# while ?ref= is not a requirement, it is recommended to use a specific commit hash / git tag to
# ensure that the kustomization is not changed in a way that breaks your deployment.
# image discovery is supported in all manifests and charts using:
Expand Down
28 changes: 0 additions & 28 deletions packages/distros/k3s/common/k3s.service

This file was deleted.

98 changes: 0 additions & 98 deletions packages/distros/k3s/common/zarf-clean-k3s.sh

This file was deleted.

55 changes: 0 additions & 55 deletions packages/distros/k3s/common/zarf.yaml

This file was deleted.

89 changes: 83 additions & 6 deletions packages/distros/k3s/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,33 @@ metadata:
name: distro-k3s
description: Used to establish a new Zarf cluster

variables:
- name: K3S_ARGS
description: Arguments to pass to K3s
default: --disable traefik

components:
# AMD-64 version of the K3s stack
- name: k3s
import:
path: common
name: k3s
only:
localOS: linux
cluster:
architecture: amd64
description: >
*** REQUIRES ROOT (not sudo) ***
Install K3s, a certified Kubernetes distribution built for IoT & Edge computing.
K3s provides the cluster need for Zarf running in Appliance Mode as well as can
host a low-resource Gitops Service if not using an existing Kubernetes platform.
files:
# K3s removal script
- source: zarf-clean-k3s.sh
target: /opt/zarf/zarf-clean-k3s.sh
executable: true
# The K3s systemd service definition
- source: k3s.service
target: /etc/systemd/system/k3s.service
symlinks:
- /etc/systemd/system/multi-user.target.wants/k3s.service
# Include the actual K3s binary
- source: https://github.com/k3s-io/k3s/releases/download/v1.28.4+k3s2/k3s
shasum: 9014535a4cd20c788282d60398a06279983562093455b53ab76701539ce67acf
Expand All @@ -29,20 +46,56 @@ components:
target: /var/lib/rancher/k3s/agent/images/k3s.tar.zst
actions:
onDeploy:
defaults:
maxRetries: 5
before:
- cmd: if [ "$(uname -m)" != "x86_64" ]; then echo "this package architecture is amd64, but the target system has a different architecture. These architectures must be the same" && exit 1; fi
description: Check that the host architecture matches the package architecture
maxRetries: 0
- cmd: ./zarf internal is-valid-hostname
maxRetries: 0
description: Check if the current system has a, RFC1123 compliant hostname
# If running RHEL variant, disable firewalld
# https://rancher.com/docs/k3s/latest/en/advanced/#additional-preparation-for-red-hat-centos-enterprise-linux
# NOTE: The empty echo prevents infinite retry loops on non-RHEL systems where the exit code would be an error
- cmd: "[ -e /etc/redhat-release ] && systemctl disable firewalld --now || echo ''"
description: If running a RHEL variant, disable 'firewalld' per k3s docs
after:
# Configure K3s systemd service
- cmd: systemctl daemon-reload
description: Reload the system services
- cmd: systemctl enable k3s
description: Enable 'k3s' to run at system boot
- cmd: systemctl restart k3s
description: Start the 'k3s' system service
onRemove:
before:
- cmd: /opt/zarf/zarf-clean-k3s.sh
description: Remove 'k3s' from the system
- cmd: rm /opt/zarf/zarf-clean-k3s.sh
description: Remove the cleanup script

# ARM-64 version of the K3s stack
- name: k3s
import:
path: common
name: k3s
only:
localOS: linux
cluster:
architecture: arm64
description: >
*** REQUIRES ROOT (not sudo) ***
Install K3s, a certified Kubernetes distribution built for IoT & Edge computing.
K3s provides the cluster need for Zarf running in Appliance Mode as well as can
host a low-resource Gitops Service if not using an existing Kubernetes platform.
files:
# K3s removal script
- source: zarf-clean-k3s.sh
target: /opt/zarf/zarf-clean-k3s.sh
executable: true
# The K3s systemd service definition
- source: k3s.service
target: /etc/systemd/system/k3s.service
symlinks:
- /etc/systemd/system/multi-user.target.wants/k3s.service
# Include the actual K3s binary
- source: https://github.com/k3s-io/k3s/releases/download/v1.28.4+k3s2/k3s-arm64
shasum: 1ae72ca06d3302f3e86ef92e6e8f84e14a084da69564e87d6e2e75f62e72388d
Expand All @@ -59,7 +112,31 @@ components:
target: /var/lib/rancher/k3s/agent/images/k3s.tar.zst
actions:
onDeploy:
defaults:
maxRetries: 5
before:
- cmd: if [ "$(uname -m)" != "aarch64" ] && [ "$(uname -m)" != "arm64" ]; then echo "this package architecture is arm64, but the target system has a different architecture. These architectures must be the same" && exit 1; fi
description: Check that the host architecture matches the package architecture
maxRetries: 0
- cmd: ./zarf internal is-valid-hostname
maxRetries: 0
description: Check if the current system has a, RFC1123 compliant hostname
# If running RHEL variant, disable firewalld
# https://rancher.com/docs/k3s/latest/en/advanced/#additional-preparation-for-red-hat-centos-enterprise-linux
# NOTE: The empty echo prevents infinite retry loops on non-RHEL systems where the exit code would be an error
- cmd: "[ -e /etc/redhat-release ] && systemctl disable firewalld --now || echo ''"
description: If running a RHEL variant, disable 'firewalld' per k3s docs
after:
# Configure K3s systemd service
- cmd: systemctl daemon-reload
description: Reload the system services
- cmd: systemctl enable k3s
description: Enable 'k3s' to run at system boot
- cmd: systemctl restart k3s
description: Start the 'k3s' system service
onRemove:
before:
- cmd: /opt/zarf/zarf-clean-k3s.sh
description: Remove 'k3s' from the system
- cmd: rm /opt/zarf/zarf-clean-k3s.sh
description: Remove the cleanup script
22 changes: 10 additions & 12 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/zarf-dev/zarf/src/internal/dns"
"github.com/zarf-dev/zarf/src/internal/packager2"
"github.com/zarf-dev/zarf/src/pkg/cluster"
"github.com/zarf-dev/zarf/src/pkg/lint"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/packager"
"github.com/zarf-dev/zarf/src/pkg/packager/filters"
Expand Down Expand Up @@ -59,19 +58,18 @@ var packageCreateCmd = &cobra.Command{
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper)

pkgClient, err := packager.New(&pkgConfig)
if err != nil {
return err
}
defer pkgClient.ClearTempPaths()

err = pkgClient.Create(cmd.Context())
var lintErr *lint.LintError
if errors.As(err, &lintErr) {
common.PrintFindings(lintErr)
opt := packager2.CreateOptions{
Flavor: pkgConfig.CreateOpts.Flavor,
RegistryOverrides: pkgConfig.CreateOpts.RegistryOverrides,
SigningKeyPath: pkgConfig.CreateOpts.SigningKeyPath,
SigningKeyPassword: pkgConfig.CreateOpts.SigningKeyPassword,
SetVariables: pkgConfig.CreateOpts.SetVariables,
MaxPackageSizeMB: pkgConfig.CreateOpts.MaxPackageSizeMB,
Output: pkgConfig.CreateOpts.Output,
}
err := packager2.Create(cmd.Context(), pkgConfig.CreateOpts.BaseDir, opt)
if err != nil {
return fmt.Errorf("failed to create package: %w", err)
return err
}
return nil
},
Expand Down
37 changes: 37 additions & 0 deletions src/internal/packager2/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

package packager2

import (
"context"

layout2 "github.com/zarf-dev/zarf/src/internal/packager2/layout"
)

type CreateOptions struct {
Flavor string
RegistryOverrides map[string]string
SigningKeyPath string
SigningKeyPassword string
SetVariables map[string]string
MaxPackageSizeMB int
Output string
}

func Create(ctx context.Context, packagePath string, opt CreateOptions) error {
createOpt := layout2.CreateOptions{
Flavor: opt.Flavor,
RegistryOverrides: opt.RegistryOverrides,
SigningKeyPath: opt.SigningKeyPath,
SigningKeyPassword: opt.SigningKeyPassword,
SetVariables: opt.SetVariables,
MaxPackageSizeMB: opt.MaxPackageSizeMB,
Output: opt.Output,
}
_, err := layout2.CreatePackage(ctx, packagePath, createOpt)
if err != nil {
return err
}
return nil
}
Loading

0 comments on commit 6879878

Please sign in to comment.