Skip to content

Commit

Permalink
Fix OS migration bug (#95)
Browse files Browse the repository at this point in the history
* Add --gpg-auto-import-keys flag to migration cmd

* Remove gpg key import

* Simplify service creation

* Remove unnecessary repoPath

* Fix OS unit tests
  • Loading branch information
ipetrov117 authored Sep 24, 2024
1 parent ac6f370 commit 4d36a61
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 34 deletions.
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

0 comments on commit 4d36a61

Please sign in to comment.