mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-21 06:31:11 +02:00
Fixes: https://github.com/talos-systems/talos/issues/3209 Using parts of `kubectl` package to run the editor. Also using the same approach as in `kubectl edit` command: - add commented section to the top of the file with the description. - if the config has errors, display validation errors in the commented section at the top of the file. - retry apply config until it succeeds. - abort if no changes were detected or if the edited file is empty. Patch currently supports jsonpatch only and can read it either from the file or from the inline argument. https://asciinema.org/a/wPawpctjoCFbJZKo2z2ATDXeC Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
// +build integration_cli
|
|
|
|
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/talos-systems/talos/internal/integration/base"
|
|
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
|
|
"github.com/talos-systems/talos/pkg/machinery/constants"
|
|
)
|
|
|
|
// PatchSuite verifies dmesg command.
|
|
type PatchSuite struct {
|
|
base.CLISuite
|
|
}
|
|
|
|
// SuiteName ...
|
|
func (suite *PatchSuite) SuiteName() string {
|
|
return "cli.PatchSuite"
|
|
}
|
|
|
|
// TestSuccess successful run.
|
|
func (suite *PatchSuite) TestSuccess() {
|
|
node := suite.RandomDiscoveredNode(machine.TypeControlPlane)
|
|
|
|
patch := []map[string]interface{}{
|
|
{
|
|
"op": "replace",
|
|
"path": "/cluster/proxy",
|
|
"value": map[string]interface{}{
|
|
"image": fmt.Sprintf("%s:v%s", constants.KubeProxyImage, constants.DefaultKubernetesVersion),
|
|
},
|
|
},
|
|
}
|
|
|
|
data, err := json.Marshal(patch)
|
|
suite.Require().NoError(err)
|
|
|
|
suite.RunCLI([]string{"patch", "--nodes", node, "--patch", string(data), "config", "--immediate"})
|
|
}
|
|
|
|
// TestError runs comand with error.
|
|
func (suite *PatchSuite) TestError() {
|
|
node := suite.RandomDiscoveredNode(machine.TypeControlPlane)
|
|
|
|
patch := []map[string]interface{}{
|
|
{
|
|
"op": "crash",
|
|
"path": "/cluster/proxy",
|
|
"value": map[string]interface{}{
|
|
"image": fmt.Sprintf("%s:v%s", constants.KubeProxyImage, constants.DefaultKubernetesVersion),
|
|
},
|
|
},
|
|
}
|
|
|
|
data, err := json.Marshal(patch)
|
|
suite.Require().NoError(err)
|
|
|
|
suite.RunCLI([]string{"patch", "--nodes", node, "--patch", string(data), "config"},
|
|
base.StderrNotEmpty(), base.StdoutEmpty(), base.ShouldFail())
|
|
suite.RunCLI([]string{"patch", "--nodes", node, "--patch", string(data), "config", "v1alpha2"},
|
|
base.StderrNotEmpty(), base.StdoutEmpty(), base.ShouldFail())
|
|
suite.RunCLI([]string{"patch", "--nodes", node, "--patch-file", "/nnnope", "config"},
|
|
base.StderrNotEmpty(), base.StdoutEmpty(), base.ShouldFail())
|
|
suite.RunCLI([]string{"patch", "--nodes", node, "--patch", "it's not even a json", "config"},
|
|
base.StderrNotEmpty(), base.StdoutEmpty(), base.ShouldFail())
|
|
}
|
|
|
|
func init() {
|
|
allSuites = append(allSuites, new(PatchSuite))
|
|
}
|