Skip to content

Commit

Permalink
accept custom cluster config locations (#153)
Browse files Browse the repository at this point in the history
* accept custom cluster config locations

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* use yaml.v3

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* go mod tidy

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* added custom root and config flag in cluster properties

* remove ClusterRootPath

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

* go mod tidy

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>

---------

Signed-off-by: Nianyu Shen <xiaoyu9964@gmail.com>
Co-authored-by: Piyush Kumar <k17piyush@gmail.com>
  • Loading branch information
nianyush and kpiyush17 authored Aug 21, 2024
1 parent b2a1268 commit 851cc01
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions clusterplugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Cluster struct {

// LocalImagesPath path to local archive images to load into containerd from the filesystem start
LocalImagesPath string `yaml:"local_images_path,omitempty" json:"local_images_path,omitempty"`

// ClusterConfigPath path to the file where the final init config will be generated
ClusterConfigPath string `yaml:"clusterConfigPath,omitempty" json:"clusterConfigPath,omitempty"`
}

type Config struct {
Expand Down
10 changes: 8 additions & 2 deletions clusterplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/kairos-io/kairos-sdk/bus"
"github.com/mudler/go-pluggable"
yip "github.com/mudler/yip/pkg/schema"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

const clusterProviderCloudConfigFile = "/usr/local/cloud-config/cluster.kairos.yaml"
Expand Down Expand Up @@ -47,8 +47,14 @@ func (p ClusterPlugin) onBoot(event *pluggable.Event) pluggable.EventResponse {
// request the cloud configuration of the provider
cc := p.Provider(*config.Cluster)

configFilePath := clusterProviderCloudConfigFile

if len(config.Cluster.ClusterConfigPath) != 0 {
configFilePath = config.Cluster.ClusterConfigPath
}

// open our cloud configuration file for writing
f, err := filesystem.OpenFile(clusterProviderCloudConfigFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
f, err := filesystem.OpenFile(configFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
if err != nil {
response.Error = fmt.Sprintf("failed to parse boot event: %s", err.Error())
return response
Expand Down
2 changes: 1 addition & 1 deletion collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
. "github.com/kairos-io/kairos-sdk/collector"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v1"
"gopkg.in/yaml.v3"
)

var _ = Describe("Config Collector", func() {
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWK
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5 h1:FaZD86+A9mVt7lh9glAryzQblMsbJYU2VnrdZ8yHlTs=
github.com/mudler/go-pluggable v0.0.0-20230126220627-7710299a0ae5/go.mod h1:WmKcT8ONmhDQIqQ+HxU+tkGWjzBEyY/KFO8LTGCu4AI=
github.com/mudler/yip v1.9.2 h1:yPR+cK3SZkEAt0uQYCeOayhcM3lyP2Py+r0ruy94Mrg=
Expand Down Expand Up @@ -467,7 +466,6 @@ github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80Lrr
github.com/zcalusic/sysinfo v1.1.0 h1:79Hqn8h4poVz6T57/4ezXbT5ZkZbZm7u1YU1C4paMyk=
github.com/zcalusic/sysinfo v1.1.0/go.mod h1:NX+qYnWGtJVPV0yWldff9uppNKU4h40hJIRPf/pGLv4=
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1 h1:A/5uWzF44DlIgdm/PQFwfMkW0JX+cIcQi/SwLAmZP5M=
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
2 changes: 1 addition & 1 deletion utils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"encoding/json"
"gopkg.in/yaml.v1"
"gopkg.in/yaml.v3"
"math/rand"
"strings"
)
Expand Down

0 comments on commit 851cc01

Please sign in to comment.