Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OS migration bug #95

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api/v1alpha1/releasemanifest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ type KubernetesDistribution struct {
}

type OperatingSystem struct {
Version string `json:"version"`
ZypperID string `json:"zypperID"`
CPEScheme string `json:"cpeScheme"`
RepoGPGPath string `json:"repoGPGPath"`
Version string `json:"version"`
ZypperID string `json:"zypperID"`
CPEScheme string `json:"cpeScheme"`
// +kubebuilder:validation:MinItems=1
SupportedArchs []Arch `json:"supportedArchs"`
PrettyName string `json:"prettyName"`
Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/lifecycle.suse.com_releasemanifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ spec:
type: string
prettyName:
type: string
repoGPGPath:
type: string
supportedArchs:
items:
enum:
Expand All @@ -84,7 +82,6 @@ spec:
required:
- cpeScheme
- prettyName
- repoGPGPath
- supportedArchs
- version
- zypperID
Expand Down
1 change: 0 additions & 1 deletion config/samples/lifecycle_v1alpha1_releasemanifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
version: "6.0"
zypperID: "SL-Micro"
cpeScheme: "cpe:/o:suse:sl-micro:6.0"
repoGPGPath: "/usr/lib/rpm/gnupg/keys/gpg-pubkey-09d9ea69-645b99ce.asc"
prettyName: "SUSE Linux Micro 6.0"
supportedArchs:
- "x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ spec:
type: string
prettyName:
type: string
repoGPGPath:
type: string
supportedArchs:
items:
enum:
Expand All @@ -82,7 +80,6 @@ spec:
required:
- cpeScheme
- prettyName
- repoGPGPath
- supportedArchs
- version
- zypperID
Expand Down
14 changes: 6 additions & 8 deletions internal/upgrade/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ func OSUpgradeSecret(nameSuffix string, releaseOS *lifecyclev1alpha1.OperatingSy
}

values := struct {
CPEScheme string
RepoGPGKey string
ZypperID string
Version string
CPEScheme string
ZypperID string
Version string
}{
CPEScheme: releaseOS.CPEScheme,
RepoGPGKey: releaseOS.RepoGPGPath,
ZypperID: releaseOS.ZypperID,
Version: releaseOS.Version,
CPEScheme: releaseOS.CPEScheme,
ZypperID: releaseOS.ZypperID,
Version: releaseOS.Version,
}

var buff bytes.Buffer
Expand Down
10 changes: 4 additions & 6 deletions internal/upgrade/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const (

func TestOSUpgradeSecret(t *testing.T) {
os := &lifecyclev1alpha1.OperatingSystem{
Version: "6.0",
ZypperID: "SL-Micro",
CPEScheme: "some-cpe-scheme",
RepoGPGPath: "some-gpg-path",
Version: "6.0",
ZypperID: "SL-Micro",
CPEScheme: "some-cpe-scheme",
}
annotations := map[string]string{
"lifecycle.suse.com/x": "z",
Expand All @@ -42,8 +41,7 @@ func TestOSUpgradeSecret(t *testing.T) {
require.NotEmpty(t, scriptContents)

assert.Contains(t, scriptContents, "RELEASE_CPE=some-cpe-scheme")
assert.Contains(t, scriptContents, "/usr/sbin/transactional-update --continue run rpm --import some-gpg-path")
assert.Contains(t, scriptContents, "/usr/sbin/transactional-update --continue run zypper migration --non-interactive --product SL-Micro/6.0/${SYSTEM_ARCH} --root /")
assert.Contains(t, scriptContents, "/usr/sbin/transactional-update --continue run zypper migration --gpg-auto-import-keys --non-interactive --product SL-Micro/6.0/${SYSTEM_ARCH} --root /")
}

func TestOSControlPlanePlan(t *testing.T) {
Expand Down
14 changes: 5 additions & 9 deletions internal/upgrade/templates/os-upgrade.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@ executeUpgrade(){
CURRENT_CPE=`cat /etc/os-release | grep -w CPE_NAME | cut -d "=" -f 2 | tr -d '"'`

SYSTEM_ARCH=`arch`
# Lines that will be appended to the systemd.service 'ExecStartPre' configuration
EXEC_START_PRE_LINES=""

# Determine whether this is a package update or a migration
if [ "${RELEASE_CPE}" == "${CURRENT_CPE}" ]; then
# Package update if both CPEs are the same
EXEC_START="/usr/sbin/transactional-update cleanup up"
EXEC_START="ExecStart=/usr/sbin/transactional-update cleanup up"
SERVICE_NAME="os-pkg-update.service"
else
# Migration if the CPEs are different
EXEC_START_PRE_PKG_UPGRADE="ExecStartPre=/usr/sbin/transactional-update cleanup up"
EXEC_START_PRE_RPM_IMPORT="ExecStartPre=/usr/sbin/transactional-update --continue run rpm --import {{.RepoGPGKey}}"
EXEC_START_PRE_LINES=$(echo -e "${EXEC_START_PRE_PKG_UPGRADE}\n${EXEC_START_PRE_RPM_IMPORT}")
PKG_UPDATE_CMD="ExecStart=/usr/sbin/transactional-update cleanup up"
MIGRATION_CMD="ExecStart=/usr/sbin/transactional-update --continue run zypper migration --gpg-auto-import-keys --non-interactive --product {{.ZypperID}}/{{.Version}}/${SYSTEM_ARCH} --root /"

EXEC_START="/usr/sbin/transactional-update --continue run zypper migration --non-interactive --product {{.ZypperID}}/{{.Version}}/${SYSTEM_ARCH} --root /"
EXEC_START=$(echo -e "${PKG_UPDATE_CMD}\n${MIGRATION_CMD}")
SERVICE_NAME="os-migration.service"
fi

Expand All @@ -60,10 +57,9 @@ After=network.target

[Service]
Type=oneshot
${EXEC_START_PRE_LINES:+$EXEC_START_PRE_LINES
}ExecStart=${EXEC_START}
IOSchedulingClass=best-effort
IOSchedulingPriority=7
${EXEC_START}
EOF

echo "Starting ${SERVICE_NAME}..."
Expand Down