From 82c39a8f4beec859d00459f3f59baa2ca041372c Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Fri, 12 Dec 2025 15:58:24 +0300 Subject: [PATCH 1/5] [feature] check settings Signed-off-by: Stepan Paksashvili --- go.mod | 4 +- go.sum | 4 +- .../models/hooks/kind/batch_hook.go | 4 + pkg/module_manager/models/hooks/kind/check.go | 96 +++++++++++++++++++ .../models/hooks/kind/config.go | 5 +- 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 pkg/module_manager/models/hooks/kind/check.go diff --git a/go.mod b/go.mod index 5a9095d15..db4873deb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckhouse/deckhouse/pkg/log v0.1.0 github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 - github.com/deckhouse/module-sdk v0.5.0 + github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c github.com/dominikbraun/graph v0.23.0 github.com/ettle/strcase v0.2.0 github.com/flant/kube-client v1.5.0 @@ -140,7 +140,7 @@ require ( github.com/google/go-containerregistry v0.20.6 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect - github.com/google/uuid v1.6.0 // indirect + github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.1 // indirect github.com/gosuri/uitable v0.0.4 // indirect diff --git a/go.sum b/go.sum index 751b567a7..5dec88532 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,8 @@ github.com/deckhouse/deckhouse/pkg/log v0.1.0 h1:2aPfyiHHSIJlX4x7ysyPOaIb7CLmyY+ github.com/deckhouse/deckhouse/pkg/log v0.1.0/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw= github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 h1:xZvbKuexrSQGEw6CB4n3UC7XbOb9QNLbm8UhcGZ2R1I= github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0/go.mod h1:Rz++SzCLkFW03WGgftnn91TimGU2shiKb5S/YuxcBuE= -github.com/deckhouse/module-sdk v0.5.0 h1:b2GJUzMKQLr7oJVJy5lXHvyymNyvNiFXpBie7MwEWwE= -github.com/deckhouse/module-sdk v0.5.0/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= +github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c h1:8KUxtE8Ubb9vAjvE+A3JFCLdUMfVm4KgyBWSNIhspLI= +github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= diff --git a/pkg/module_manager/models/hooks/kind/batch_hook.go b/pkg/module_manager/models/hooks/kind/batch_hook.go index 981b3fc89..aff57e04c 100644 --- a/pkg/module_manager/models/hooks/kind/batch_hook.go +++ b/pkg/module_manager/models/hooks/kind/batch_hook.go @@ -303,6 +303,10 @@ func remapSDKConfigToConfig(input *sdkhook.BatchHookConfig) (*BatchHookConfig, e cfg.Readiness = input.Readiness cfg.Hooks[BatchHookReadyKey] = input.Readiness } + + if input.HasSettingsCheck { + cfg.HasSettingsCheck = true + } default: return nil, fmt.Errorf("unknown version '%s'", input.Version) } diff --git a/pkg/module_manager/models/hooks/kind/check.go b/pkg/module_manager/models/hooks/kind/check.go new file mode 100644 index 000000000..d3fd7d888 --- /dev/null +++ b/pkg/module_manager/models/hooks/kind/check.go @@ -0,0 +1,96 @@ +// Copyright 2025 Flant JSC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package kind + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "log/slog" + "os" + "path/filepath" + "strings" + + "github.com/deckhouse/deckhouse/pkg/log" + "github.com/deckhouse/module-sdk/pkg/settingscheck" + "github.com/flant/shell-operator/pkg/executor" + "github.com/google/uuid" + + "github.com/flant/addon-operator/pkg/utils" +) + +type SettingsCheck struct { + path string + tmp string + logger *log.Logger +} + +func NewSettingsCheck(path, tmpPath string, logger *log.Logger) *SettingsCheck { + return &SettingsCheck{ + path: path, + tmp: tmpPath, + logger: logger, + } +} + +// Check runs the setting check via the OS interpreter and returns the result of the execution +func (c *SettingsCheck) Check(ctx context.Context, settings utils.Values) (*settingscheck.Result, error) { + // tmp files has uuid in name and create only in tmp folder (because of RO filesystem) + tmp, err := c.prepareTmpFile(settings) + if err != nil { + return nil, err + } + + // Remove tmp files after execution + defer func() { + if err = os.Remove(tmp); err != nil { + c.logger.Error("remove tmp file", slog.String("file", tmp), log.Err(err)) + } + }() + + envs := os.Environ() + envs = append(envs, fmt.Sprintf("%s=%s", settingscheck.EnvSettingsPath, tmp)) + + result := &settingscheck.Result{ + Allow: true, + } + + cmd := executor.NewExecutor("", c.path, []string{"hook", "check"}, envs).WithLogger(c.logger.Named("executor")) + if _, err = cmd.RunAndLogLines(ctx, make(map[string]string)); err != nil { + trimmed := bytes.NewBufferString(strings.TrimPrefix(err.Error(), "stderr:")) + + if err = json.NewDecoder(trimmed).Decode(result); err != nil { + return nil, fmt.Errorf("parse output: %s", err) + } + } + + return result, nil +} + +// prepareTmpFile creates temporary files for hook and returns environment variables with paths +func (c *SettingsCheck) prepareTmpFile(settings utils.Values) (string, error) { + data, err := settings.JsonBytes() + if err != nil { + return "", err + } + + path := filepath.Join(c.tmp, fmt.Sprintf("%s.json", uuid.New().String())) + if err = utils.DumpData(path, data); err != nil { + return "", err + } + + return path, err +} diff --git a/pkg/module_manager/models/hooks/kind/config.go b/pkg/module_manager/models/hooks/kind/config.go index b157838e6..846edd2ca 100644 --- a/pkg/module_manager/models/hooks/kind/config.go +++ b/pkg/module_manager/models/hooks/kind/config.go @@ -5,6 +5,7 @@ import sdkhook "github.com/deckhouse/module-sdk/pkg/hook" const BatchHookReadyKey = "ready" type BatchHookConfig struct { - Hooks map[string]*sdkhook.HookConfig - Readiness *sdkhook.HookConfig + Hooks map[string]*sdkhook.HookConfig + Readiness *sdkhook.HookConfig + HasSettingsCheck bool } From 5734510f9d010865a32e112b924ced0da48d3e13 Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Fri, 12 Dec 2025 16:34:22 +0300 Subject: [PATCH 2/5] [feature] check settings Signed-off-by: Stepan Paksashvili --- pkg/module_manager/models/hooks/kind/check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/module_manager/models/hooks/kind/check.go b/pkg/module_manager/models/hooks/kind/check.go index d3fd7d888..8fd1c7d88 100644 --- a/pkg/module_manager/models/hooks/kind/check.go +++ b/pkg/module_manager/models/hooks/kind/check.go @@ -26,10 +26,10 @@ import ( "github.com/deckhouse/deckhouse/pkg/log" "github.com/deckhouse/module-sdk/pkg/settingscheck" - "github.com/flant/shell-operator/pkg/executor" "github.com/google/uuid" "github.com/flant/addon-operator/pkg/utils" + "github.com/flant/shell-operator/pkg/executor" ) type SettingsCheck struct { From 1fbea7d6af94bab6caf60e8260d6d38280b17bca Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Tue, 16 Dec 2025 15:34:33 +0300 Subject: [PATCH 3/5] [feature] check settings Signed-off-by: Stepan Paksashvili --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index db4873deb..03a43c35b 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckhouse/deckhouse/pkg/log v0.1.0 github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 - github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c + github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547 github.com/dominikbraun/graph v0.23.0 github.com/ettle/strcase v0.2.0 github.com/flant/kube-client v1.5.0 diff --git a/go.sum b/go.sum index 5dec88532..f17d371e0 100644 --- a/go.sum +++ b/go.sum @@ -104,6 +104,8 @@ github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 h1:xZvbKuexrSQGEw6CB4n github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0/go.mod h1:Rz++SzCLkFW03WGgftnn91TimGU2shiKb5S/YuxcBuE= github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c h1:8KUxtE8Ubb9vAjvE+A3JFCLdUMfVm4KgyBWSNIhspLI= github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= +github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547 h1:EDFoe9mEb2wECXdVYrUQ3GUYPYWRrBWKQBDvEBytyFQ= +github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= From 0a0d7f0abb26e1cc4f14208454d5b9b790002fbe Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Wed, 17 Dec 2025 15:37:43 +0300 Subject: [PATCH 4/5] [feature] check settings Signed-off-by: Stepan Paksashvili --- go.mod | 2 +- go.sum | 2 ++ pkg/module_manager/models/hooks/kind/check.go | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 03a43c35b..d20028dcc 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckhouse/deckhouse/pkg/log v0.1.0 github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 - github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547 + github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c github.com/dominikbraun/graph v0.23.0 github.com/ettle/strcase v0.2.0 github.com/flant/kube-client v1.5.0 diff --git a/go.sum b/go.sum index f17d371e0..8031cdef7 100644 --- a/go.sum +++ b/go.sum @@ -106,6 +106,8 @@ github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c h1:8KUxtE8U github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547 h1:EDFoe9mEb2wECXdVYrUQ3GUYPYWRrBWKQBDvEBytyFQ= github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= +github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c h1:kzaKVef2TdCnNnN3M0ZtiJWx/htlqrtgCa2djbOBGgk= +github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= diff --git a/pkg/module_manager/models/hooks/kind/check.go b/pkg/module_manager/models/hooks/kind/check.go index 8fd1c7d88..1b3e270dd 100644 --- a/pkg/module_manager/models/hooks/kind/check.go +++ b/pkg/module_manager/models/hooks/kind/check.go @@ -47,11 +47,11 @@ func NewSettingsCheck(path, tmpPath string, logger *log.Logger) *SettingsCheck { } // Check runs the setting check via the OS interpreter and returns the result of the execution -func (c *SettingsCheck) Check(ctx context.Context, settings utils.Values) (*settingscheck.Result, error) { +func (c *SettingsCheck) Check(ctx context.Context, settings utils.Values) (settingscheck.Result, error) { // tmp files has uuid in name and create only in tmp folder (because of RO filesystem) tmp, err := c.prepareTmpFile(settings) if err != nil { - return nil, err + return settingscheck.Result{}, err } // Remove tmp files after execution @@ -64,16 +64,16 @@ func (c *SettingsCheck) Check(ctx context.Context, settings utils.Values) (*sett envs := os.Environ() envs = append(envs, fmt.Sprintf("%s=%s", settingscheck.EnvSettingsPath, tmp)) - result := &settingscheck.Result{ - Allow: true, + result := settingscheck.Result{ + Valid: true, } cmd := executor.NewExecutor("", c.path, []string{"hook", "check"}, envs).WithLogger(c.logger.Named("executor")) if _, err = cmd.RunAndLogLines(ctx, make(map[string]string)); err != nil { trimmed := bytes.NewBufferString(strings.TrimPrefix(err.Error(), "stderr:")) - if err = json.NewDecoder(trimmed).Decode(result); err != nil { - return nil, fmt.Errorf("parse output: %s", err) + if err = json.NewDecoder(trimmed).Decode(&result); err != nil { + return settingscheck.Result{}, fmt.Errorf("parse output: %s", err) } } From 987f13c6fbdec397717259cc6f739057b3770640 Mon Sep 17 00:00:00 2001 From: Stepan Paksashvili Date: Thu, 18 Dec 2025 11:59:17 +0300 Subject: [PATCH 5/5] [feature] check settings Signed-off-by: Stepan Paksashvili --- go.mod | 2 +- go.sum | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index d20028dcc..78083737c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckhouse/deckhouse/pkg/log v0.1.0 github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 - github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c + github.com/deckhouse/module-sdk v0.6.0 github.com/dominikbraun/graph v0.23.0 github.com/ettle/strcase v0.2.0 github.com/flant/kube-client v1.5.0 diff --git a/go.sum b/go.sum index 8031cdef7..08a8cc26b 100644 --- a/go.sum +++ b/go.sum @@ -102,12 +102,8 @@ github.com/deckhouse/deckhouse/pkg/log v0.1.0 h1:2aPfyiHHSIJlX4x7ysyPOaIb7CLmyY+ github.com/deckhouse/deckhouse/pkg/log v0.1.0/go.mod h1:pbAxTSDcPmwyl3wwKDcEB3qdxHnRxqTV+J0K+sha8bw= github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0 h1:xZvbKuexrSQGEw6CB4n3UC7XbOb9QNLbm8UhcGZ2R1I= github.com/deckhouse/deckhouse/pkg/metrics-storage v0.3.0/go.mod h1:Rz++SzCLkFW03WGgftnn91TimGU2shiKb5S/YuxcBuE= -github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c h1:8KUxtE8Ubb9vAjvE+A3JFCLdUMfVm4KgyBWSNIhspLI= -github.com/deckhouse/module-sdk v0.5.1-0.20251212125257-4a30b394802c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= -github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547 h1:EDFoe9mEb2wECXdVYrUQ3GUYPYWRrBWKQBDvEBytyFQ= -github.com/deckhouse/module-sdk v0.5.1-0.20251216123127-c45654f3e547/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= -github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c h1:kzaKVef2TdCnNnN3M0ZtiJWx/htlqrtgCa2djbOBGgk= -github.com/deckhouse/module-sdk v0.5.1-0.20251217123610-0575dd4d736c/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= +github.com/deckhouse/module-sdk v0.6.0 h1:CuyiLEkPr/3dRYzvvvzR0pInTMSEeThrURuFesIehHE= +github.com/deckhouse/module-sdk v0.6.0/go.mod h1:+EbBnP8z+poIihgL4l1oxHng5ePqDUK44c39u7sEBss= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=