const string for Version, Release, Confversion

The Version (e,g, 4.4 ), Release (git hash) and Confversion (e.g. 44)
must be compiled into the code so that they can't be changed during run
time and ensure this with the compiler

Signed-off-by: Christian Goll <cgoll@suse.com>
This commit is contained in:
Christian Goll
2024-01-26 13:03:43 +01:00
committed by Jonathon Anderson
parent 841d4cf674
commit ff10bc95bb
14 changed files with 19 additions and 22 deletions

View File

@@ -14,6 +14,7 @@ VARLIST := OS
VARLIST += WAREWULF VERSION RELEASE
WAREWULF ?= warewulf
VERSION ?= 4.5.x
GIT_TAG := $(shell test -e .git && git log -1 --format="%h")
ifdef GIT_TAG

View File

@@ -1,4 +1,4 @@
WW_INTERNAL: 43
WW_INTERNAL: 45
nodeprofiles:
default:
comment: This profile is automatically included for each node

View File

@@ -283,7 +283,7 @@ A sample configuration file for a typical deployment, with all
dependent services enabled.
.EX
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 10.0.0.1
network: 10.0.0.0
netmask: 255.255.0.0

View File

@@ -87,6 +87,7 @@ func rootPersistentPreRunE(cmd *cobra.Command, args []string) (err error) {
}
}
if err != nil {
wwlog.Error("version: %s relase: %s WW_INTERNAL: %s", warewulfconf.Version, warewulfconf.Release, warewulfconf.Confversion)
return
}
err = conf.SetDynamicDefaults()

View File

@@ -14,17 +14,13 @@ type BuildConfig struct {
WWChrootdir string `default:"@WWCHROOTDIR@"`
WWProvisiondir string `default:"@WWPROVISIONDIR@"`
WWClientdir string `default:"@WWCLIENTDIR@"`
version string `default:"@VERSION@"`
release string `default:"@RELEASE@"`
}
func (conf BuildConfig) Version() string {
return conf.version
}
const Version = "@VERSION@"
const Release = "@RELEASE@"
func (conf BuildConfig) Release() string {
return conf.release
}
// must be set .in file so that its available for tests
const Confversion = "45"
type TFTPConf struct {
Enabled bool `yaml:"enabled" default:"true"`

View File

@@ -51,8 +51,6 @@ func TestDefaultRootConf(t *testing.T) {
assert.NotEmpty(t, conf.Paths.WWOverlaydir)
assert.NotEmpty(t, conf.Paths.WWChrootdir)
assert.NotEmpty(t, conf.Paths.WWProvisiondir)
assert.NotEmpty(t, conf.Paths.Version)
assert.NotEmpty(t, conf.Paths.Release)
assert.NotEmpty(t, conf.Paths.WWClientdir)
}

View File

@@ -1,9 +1,10 @@
package overlay
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/warewulf/warewulf/internal/pkg/node"
"testing"
)
func Test_createIgnitionJson(t *testing.T) {

View File

@@ -11,8 +11,9 @@ import (
"path/filepath"
"testing"
warewulfconf "github.com/warewulf/warewulf/internal/pkg/config"
"github.com/stretchr/testify/assert"
"github.com/warewulf/warewulf/internal/pkg/config"
"github.com/warewulf/warewulf/internal/pkg/node"
)
@@ -62,7 +63,7 @@ func New(t *testing.T) (env *TestEnv) {
env.WriteFile(t, path.Join(Datadir, "warewulf/defaults.conf"), initDefaultsConf)
// re-read warewulf.conf
conf := config.New()
conf := warewulfconf.New()
err = conf.Read(env.GetPath(path.Join(Sysconfdir, "warewulf/warewulf.conf")))
assert.NoError(t, err)

View File

@@ -11,8 +11,7 @@ import (
Return the version of wwctl
*/
func GetVersion() string {
conf := warewulfconf.Get()
return fmt.Sprintf("%s-%s", conf.Paths.Version(), conf.Paths.Release())
return fmt.Sprintf("%s-%s", warewulfconf.Version, warewulfconf.Release)
}
/*

View File

@@ -14,7 +14,7 @@ Warewulf (4.4.0):
.. code-block:: yaml
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 10.0.0.1
netmask: 255.255.252.0
network: 10.0.0.0

View File

@@ -190,7 +190,7 @@ Vagrantfile
head.vm.provision "shell", inline: <<-SHELL
cat << 'CONF' | sudo tee /etc/warewulf/warewulf.conf
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 192.168.200.254
netmask: 255.255.255.0
network: 192.168.200.0

View File

@@ -64,7 +64,7 @@ address of your cluster's private network interface:
.. code-block:: yaml
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 192.168.200.1
netmask: 255.255.255.0
network: 192.168.200.0

View File

@@ -57,7 +57,7 @@ address of your cluster's private network interface:
.. code-block:: yaml
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 192.168.200.1
netmask: 255.255.255.0
network: 192.168.200.0

View File

@@ -57,7 +57,7 @@ address of your cluster's private network interface:
.. code-block:: yaml
WW_INTERNAL: 43
WW_INTERNAL: 45
ipaddr: 192.168.200.1
netmask: 255.255.255.0
network: 192.168.200.0