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

Some small fixes here and there #661

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kairos-io/kairos-agent/v2

go 1.23.1
go 1.23.6

require (
github.com/Masterminds/semver/v3 v3.3.1
Expand Down Expand Up @@ -39,8 +39,7 @@ require (
require (
github.com/distribution/reference v0.6.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/google/go-github/v66 v66.0.0
github.com/google/go-github/v69 v69.0.0
github.com/google/go-github/v68 v68.0.0
github.com/twpayne/go-vfs/v5 v5.0.4
)

Expand Down
117 changes: 17 additions & 100 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
Expand Down
3 changes: 1 addition & 2 deletions internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent_test

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -23,7 +22,7 @@ echo "{}"
var _ = Describe("Bootstrap provider", func() {
Context("Config", func() {
It("gets entire content", func() {
f, err := ioutil.TempDir("", "tests")
f, err := os.MkdirTemp("", "tests")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(f)

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/hooks/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os/exec"
"syscall"

config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-sdk/bundles"
"github.com/kairos-io/kairos-sdk/machine"
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/hooks/gruboptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"strings"

config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-sdk/system"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/hooks/hook.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hook

import (
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/agent/hooks/kcrypt_uki.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type KcryptUKI struct{}
func (k KcryptUKI) Run(c config.Config, spec v1.Spec) error {
// pre-check for systemd version, we need something higher or equal to 252
run, err := utils.SH("systemctl --version | head -1 | awk '{ print $2}'")
systemdVersion := strings.TrimSpace(string(run))
systemdVersion := strings.TrimSpace(run)
if err != nil {
c.Logger.Errorf("could not get systemd version: %s", err)
c.Logger.Errorf("could not get systemd version: %s", run)
Expand Down
24 changes: 15 additions & 9 deletions internal/agent/hooks/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-sdk/machine"
"github.com/mudler/yip/pkg/schema"
yip "github.com/mudler/yip/pkg/schema"
Expand All @@ -24,7 +24,7 @@ func saveCloudConfig(name config.Stage, yc yip.YipConfig) error {
return os.WriteFile(filepath.Join("/oem", fmt.Sprintf("10_%s.yaml", name)), yipYAML, 0400)
}

// Read the keys sections ephemeral_mounts and bind mounts from install key in the cloud config.
// Run Reads the keys sections ephemeral_mounts and bind mounts from install key in the cloud config.
// If not empty write an environment file to /run/cos/custom-layout.env.
// That env file is in turn read by /overlay/files/system/oem/11_persistency.yaml in fs.after stage.
func (cm CustomMounts) Run(c config.Config, _ v1.Spec) error {
Expand All @@ -48,15 +48,21 @@ func (cm CustomMounts) Run(c config.Config, _ v1.Spec) error {
mountsList["CUSTOM_BIND_MOUNTS"] = strings.Join(c.Install.BindMounts, " ")
mountsList["CUSTOM_EPHEMERAL_MOUNTS"] = strings.Join(c.Install.EphemeralMounts, " ")

config := yip.YipConfig{Stages: map[string][]schema.Stage{
"rootfs": []yip.Stage{{
Name: "user_custom_mounts",
EnvironmentFile: "/run/cos/custom-layout.env",
Environment: mountsList,
}},
cfg := yip.YipConfig{Stages: map[string][]schema.Stage{
"rootfs": {
{
Name: "user_custom_mounts",
EnvironmentFile: "/run/cos/custom-layout.env",
Environment: mountsList,
},
},
}}

saveCloudConfig("user_custom_mounts", config) //nolint:errcheck
err := saveCloudConfig("user_custom_mounts", cfg)
if err != nil {
c.Logger.Logger.Error().Err(err).Msg("Failed to save cloud config")
return err
}
c.Logger.Logger.Debug().Msg("Finish CustomMounts hook")
return nil
}
1 change: 0 additions & 1 deletion internal/agent/iconunix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || darwin
// +build linux darwin

// File generated by 2goarray v0.1.0 (http://github.com/cratonica/2goarray)

Expand Down
17 changes: 5 additions & 12 deletions internal/agent/interactive_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agent
import (
"encoding/json"
"fmt"
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -47,14 +48,6 @@ func isYes(s string) bool {
return false
}

const (
_ = 1 << (10 * iota)
KiB
MiB
GiB
TiB
)

func promptBool(p events.YAMLPrompt) (string, error) {
def := "n"
if p.Default != "" {
Expand Down Expand Up @@ -125,7 +118,7 @@ func InteractiveInstall(debug, spawnShell bool, sourceImgURL string) error {

cmd.PrintText(agentConfig.Branding.InteractiveInstall, "Installation")

disks := []string{}
var disks []string
maxSize := float64(0)
preferedDevice := "/dev/sda"

Expand All @@ -134,12 +127,12 @@ func InteractiveInstall(debug, spawnShell bool, sourceImgURL string) error {
if strings.HasPrefix(disk.Name, "loop") || strings.HasPrefix(disk.Name, "ram") || strings.HasPrefix(disk.Name, "sr") || strings.HasPrefix(disk.Name, "zram") {
continue
}
size := float64(disk.SizeBytes) / float64(GiB)
size := float64(disk.SizeBytes) / float64(constants.GiB)
if size > maxSize {
maxSize = size
preferedDevice = "/dev/" + disk.Name
}
disks = append(disks, fmt.Sprintf("/dev/%s: (%.2f GiB) ", disk.Name, float64(disk.SizeBytes)/float64(GiB)))
disks = append(disks, fmt.Sprintf("/dev/%s: (%.2f GiB) ", disk.Name, float64(disk.SizeBytes)/float64(constants.GiB)))
}

pterm.Info.Println("Available Disks:")
Expand Down Expand Up @@ -194,7 +187,7 @@ func InteractiveInstall(debug, spawnShell bool, sourceImgURL string) error {
}

// Prompt the user by prompts defined by the provider
r := []events.YAMLPrompt{}
var r []events.YAMLPrompt

bus.Manager.Response(events.EventInteractiveInstall, func(p *pluggable.Plugin, resp *pluggable.EventResponse) {
err := json.Unmarshal([]byte(resp.Data), &r)
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package agent
import (
"fmt"

events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-agent/v2/internal/bus"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/mudler/go-pluggable"
)

Expand Down
4 changes: 3 additions & 1 deletion internal/agent/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func sharedReset(reboot, unattended, resetOem bool, dir ...string) (c *config.Co

d, err := json.Marshal(r)
if err != nil {
c.Logger.Errorf("failed to marshal reset cmdline flags/event options: %s", err)
if &c != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

this was a potential nil reference

c.Logger.Errorf("failed to marshal reset cmdline flags/event options: %s", err)
}
return c, err
}
cliConf := string(d)
Expand Down
28 changes: 3 additions & 25 deletions internal/agent/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ import (
"strings"

hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/mudler/go-pluggable"

"github.com/kairos-io/kairos-agent/v2/internal/bus"
"github.com/kairos-io/kairos-agent/v2/pkg/action"
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/uki"
internalutils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
k8sutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/k8s"
events "github.com/kairos-io/kairos-sdk/bus"
"github.com/kairos-io/kairos-sdk/collector"
"github.com/kairos-io/kairos-sdk/utils"
"github.com/kairos-io/kairos-sdk/versioneer"
Expand Down Expand Up @@ -65,9 +62,10 @@ func ListNewerReleases(includePrereleases bool) ([]string, error) {
return tagList.FullImages()
}

// Upgrade upgrades the system to the specified image and will call the underlying upgrade function
// TODO: Check where force and preReleases is being used? They dont seem to be used anywhere?
func Upgrade(
source string, force, strictValidations bool, dirs []string, upgradeEntry string, preReleases bool) error {
source string, _, strictValidations bool, dirs []string, upgradeEntry string, _ bool) error {
bus.Manager.Initialize()

fixedDirs := make([]string, len(dirs))
Expand Down Expand Up @@ -226,26 +224,6 @@ func generateUpgradeConfForCLIArgs(source, upgradeEntry string) (string, error)
return string(d), err
}

func getReleasesFromProvider(includePrereleases bool) ([]string, error) {
var result []string
bus.Manager.Response(events.EventAvailableReleases, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
if r.Data == "" {
return
}
if err := json.Unmarshal([]byte(r.Data), &result); err != nil {
fmt.Printf("warn: failed unmarshalling data: '%s'\n", err.Error())
}
})

configYAML := "IncludePreReleases: true"
_, err := bus.Manager.Publish(events.EventAvailableReleases, events.EventPayload{Config: configYAML})
if err != nil {
return result, fmt.Errorf("failed publishing event: %w", err)
}

return result, nil
}

// ExtraConfigUpgrade is the struct that holds the upgrade options that come from flags and events
type ExtraConfigUpgrade struct {
Upgrade struct {
Expand Down
5 changes: 3 additions & 2 deletions internal/webui/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webui
import (
"context"
"embed"
"errors"
"io"
"io/fs"
"log"
Expand All @@ -12,9 +13,9 @@ import (
"text/template"
"time"

"github.com/kairos-io/kairos-sdk/schema"
"github.com/kairos-io/kairos-agent/v2/internal/agent"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-sdk/schema"
"github.com/labstack/echo/v4"
process "github.com/mudler/go-processmanager"
"github.com/nxadm/tail"
Expand Down Expand Up @@ -239,7 +240,7 @@ func Start(ctx context.Context) error {

ec.GET("/ws", streamProcess(&s))

if err := ec.Start(listen); err != nil && err != http.ErrServerClosed {
if err := ec.Start(listen); err != nil && !errors.Is(err, http.ErrServerClosed) {
return err
}

Expand Down
16 changes: 0 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,8 @@ import (
"github.com/sanity-io/litter"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
)

// ReleasesToOutput gets a semver.Collection and outputs it in the given format
// Only used here.
func ReleasesToOutput(rels []string, output string) []string {
switch strings.ToLower(output) {
case "yaml":
d, _ := yaml.Marshal(rels)
return []string{string(d)}
case "json":
d, _ := json.Marshal(rels)
return []string{string(d)}
default:
return rels
}
}

var sourceFlag = cli.StringFlag{
Name: "source",
Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`",
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package action

import (
config "github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
cnst "github.com/kairos-io/kairos-agent/v2/pkg/constants"
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *ResetAction) updateInstallState(e *elemental.Elemental, cleanup *utils.
)
}

// ResetRun will reset the cos system to by following several steps
// Run will reset the cos system to by following several steps
func (r ResetAction) Run() (err error) {
e := elemental.NewElemental(r.cfg)
cleanup := utils.NewCleanStack()
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var _ = Describe("Reset action tests", func() {
bootedFrom = constants.SystemLabel
runner.SideEffect = func(cmd string, args ...string) ([]byte, error) {
if cmd == cmdFail {
return []byte{}, errors.New("Command failed")
return []byte{}, errors.New("command failed")
}
switch cmd {
case "cat":
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudinit/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (ci *YipCloudInitRunner) SetModifier(m schema.Modifier) {
ci.exec.Modifier(m)
}

// Useful for testing purposes
// SetFs sets the underlaying fs, useful for testing purposes
func (ci *YipCloudInitRunner) SetFs(fs vfs.FS) {
ci.fs = fs
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudinit/cloudinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -89,7 +89,7 @@ stages:
file, err := os.Open(temp + "/tmp/test/bar")
Expect(err).ShouldNot(HaveOccurred())

b, err := ioutil.ReadAll(file)
b, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading
Loading