Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cmd/microshift/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func newCommand() *cobra.Command {
cmd.AddCommand(cmds.NewRunMicroshiftCommand())
cmd.AddCommand(cmds.NewVersionCommand(ioStreams))
cmd.AddCommand(cmds.NewShowConfigCommand(ioStreams))
cmd.AddCommand(cmds.NewAdminCommand())
cmd.AddCommand(cmds.NewHealthCommand())
cmd.AddCommand(cmds.NewDataCommand())
return cmd
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ require (
require (
github.com/lithammer/dedent v1.1.0 // indirect
github.com/moby/ipvs v1.1.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
)

replace (
Expand Down
13 changes: 13 additions & 0 deletions packaging/greenboot/set-health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

SCRIPT_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"

if [[ "${SCRIPT_DIR}" == *"green.d"* ]]; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels tricky. Could we just have 2 scripts so we're explicitly passing the health status?

HEALTH="healthy"
else
HEALTH="unhealthy"
fi

set -x
microshift health set-current "--${HEALTH}"

14 changes: 11 additions & 3 deletions packaging/rpm/microshift.spec
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,18 @@ install -d %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}
install -m644 packaging/selinux/microshift.pp.bz2 %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}

# Greenboot scripts
install -d -m755 %{buildroot}%{_datadir}/microshift/functions
install -p -m644 packaging/greenboot/functions.sh %{buildroot}%{_datadir}/microshift/functions/greenboot.sh

install -d -m755 %{buildroot}%{_sysconfdir}/greenboot/check/required.d
install -d -m755 %{buildroot}%{_sysconfdir}/greenboot/red.d
install -p -m755 packaging/greenboot/microshift-running-check.sh %{buildroot}%{_sysconfdir}/greenboot/check/required.d/40_microshift_running_check.sh

install -d -m755 %{buildroot}%{_sysconfdir}/greenboot/red.d
install -p -m755 packaging/greenboot/microshift-pre-rollback.sh %{buildroot}%{_sysconfdir}/greenboot/red.d/40_microshift_pre_rollback.sh
install -d -m755 %{buildroot}%{_datadir}/microshift/functions
install -p -m644 packaging/greenboot/functions.sh %{buildroot}%{_datadir}/microshift/functions/greenboot.sh
install -p -m755 packaging/greenboot/set-health.sh %{buildroot}%{_sysconfdir}/greenboot/red.d/40_microshift_set_health.sh

install -d -m755 %{buildroot}%{_sysconfdir}/greenboot/green.d
install -p -m755 packaging/greenboot/set-health.sh %{buildroot}%{_sysconfdir}/greenboot/green.d/40_microshift_set_health.sh

%post

Expand Down Expand Up @@ -295,6 +301,8 @@ systemctl enable --now --quiet openvswitch || true
%files greenboot
%{_sysconfdir}/greenboot/check/required.d/40_microshift_running_check.sh
%{_sysconfdir}/greenboot/red.d/40_microshift_pre_rollback.sh
%{_sysconfdir}/greenboot/red.d/40_microshift_set_health.sh
%{_sysconfdir}/greenboot/green.d/40_microshift_set_health.sh
%{_datadir}/microshift/functions/greenboot.sh

# Use Git command to generate the log and replace the VERSION string
Expand Down
28 changes: 28 additions & 0 deletions pkg/admin/data/data_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package data
import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -42,6 +43,26 @@ func (dm *manager) BackupExists(name BackupName) (bool, error) {
return pathExists(dm.GetBackupPath(name))
}

func (dm *manager) RemoveBackup(name BackupName) error {
return os.RemoveAll(dm.GetBackupPath(name))
}

func (dm *manager) GetBackupList() ([]BackupName, error) {
files, err := os.ReadDir(config.BackupsDir)
if err != nil {
return nil, err
}

backups := make([]BackupName, 0, len(files))
for _, file := range files {
if file.IsDir() {
backups = append(backups, BackupName(file.Name()))
}
}

return backups, nil
}

func (dm *manager) Backup(name BackupName) error {
klog.InfoS("Backing up the data",
"storage", dm.storage, "name", name, "data", config.DataDir)
Expand All @@ -50,6 +71,13 @@ func (dm *manager) Backup(name BackupName) error {
return &EmptyArgErr{"name"}
}

if exists, err := dm.BackupExists(name); err != nil {
return fmt.Errorf("checking if backup %s exists failed: %w", name, err)
} else if exists {
klog.ErrorS(nil, "Backup already exists - name should be unique", "name", name)
return fmt.Errorf("backup %s already exists", name)
}

if found, err := pathExists(string(dm.storage)); err != nil {
return err
} else if !found {
Expand Down
Loading