Skip to content

Commit

Permalink
Add missing values in release file and add validator for it
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Jan 29, 2025
1 parent 70b99ec commit 4a1c08d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func GetKairosReleaseStage(sis values.System, log types.KairosLogger) []schema.S
if we have the original needed fields we can recreate the rest of the fields if needed so....
*/

IMAGE_LABEL := ""
idLike := fmt.Sprintf("kairos-%s-%s-%s", config.DefaultConfig.Variant, sis.Distro.String(), sis.Version)
flavor := sis.Distro.String()
flavorRelease := sis.Version
Expand All @@ -110,6 +111,9 @@ func GetKairosReleaseStage(sis values.System, log types.KairosLogger) []schema.S
log.Debugf("Failed to split the flavor %s", flavor)
}
}
// "24.04-standard-amd64-generic-v3.2.4-36-g24ca209-k3sv1.32.0-k3s1"
// We are not doing the k3s software version here
imageLabel := fmt.Sprintf("%s-%s-%s-%s-%s", flavorRelease, config.DefaultConfig.Variant, sis.Arch.String(), config.DefaultConfig.Model, config.DefaultConfig.FrameworkVersion)

return []schema.Stage{
{
Expand All @@ -130,6 +134,7 @@ func GetKairosReleaseStage(sis values.System, log types.KairosLogger) []schema.S
"KAIROS_BUG_REPORT_URL": "https://github.com/kairos-io/kairos/issues",
"KAIROS_HOME_URL": "https://github.com/kairos-io/kairos",
"KAIROS_RELEASE": config.DefaultConfig.FrameworkVersion, // Move to use the framework version, bump framework to be in sync with Kairos, used by upgrades
"KAIROS_IMAGE_LABEL": imageLabel, // Used by raw image creation...very bad
},
EnvironmentFile: "/etc/kairos-release",
},
Expand Down
32 changes: 32 additions & 0 deletions pkg/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validation
import (
"fmt"
"github.com/hashicorp/go-multierror"
"github.com/joho/godotenv"
"github.com/kairos-io/kairos-init/pkg/config"
"github.com/kairos-io/kairos-init/pkg/system"
"github.com/kairos-io/kairos-init/pkg/values"
Expand Down Expand Up @@ -96,6 +97,37 @@ func (v *Validator) Validate() error {
}
}

// Validate all needed keys are stored in kairos-release
keys := []string{
"KAIROS_ID",
"KAIROS_ID_LIKE", // Maybe not critical? Same as name below
"KAIROS_NAME",
"KAIROS_VERSION",
"KAIROS_ARCH",
"KAIROS_TARGETARCH", // Not critical, same as ARCH above
"KAIROS_FLAVOR",
"KAIROS_FLAVOR_RELEASE",
"KAIROS_FAMILY",
"KAIROS_MODEL",
"KAIROS_VARIANT",
"KAIROS_REGISTRY_AND_ORG",
"KAIROS_BUG_REPORT_URL", // Not critical
"KAIROS_HOME_URL", // Not critical
"KAIROS_RELEASE",
"KAIROS_IMAGE_LABEL",
}

vals, err := godotenv.Read("/etc/kairos/kairos-release")
if err != nil {
multi = multierror.Append(multi, fmt.Errorf("could not open kairos-release file"))
} else {
for _, key := range keys {
if vals[key] == "" {
multi = multierror.Append(multi, fmt.Errorf("key %s not found or empty in kairos-release", key))
}
}
}

// Check if initrd contains the necessary binaries
// Do it at the ends as its the slowest check
if !config.DefaultConfig.TrustedBoot {
Expand Down

0 comments on commit 4a1c08d

Please sign in to comment.