diff --git a/pkg/config/config.go b/pkg/config/config.go index 746bef958..709a6ef17 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -46,11 +46,19 @@ func loadRawMessages(src []string) ([]json.RawMessage, error) { var raws []json.RawMessage for _, p := range src { + if p == "-" { + r, err := loadRaw(os.Stdin) + if err != nil { + return nil, err + } + raws = append(raws, r...) + continue + } p, err := path.Expand(p) if err != nil { return nil, err } - r, err := loadRawConfig(p) + r, err := loadRawFromFile(p) if err != nil { return nil, err } @@ -426,8 +434,7 @@ func FilterWithoutTypeFromContext[T InternalObject](ctx context.Context) (out [] return FilterWithoutType[T](objs) } -func loadRawConfig(p string) ([]json.RawMessage, error) { - var raws []json.RawMessage +func loadRawFromFile(p string) ([]json.RawMessage, error) { file, err := os.Open(p) if err != nil { return nil, err @@ -435,10 +442,15 @@ func loadRawConfig(p string) ([]json.RawMessage, error) { defer func() { _ = file.Close() }() - decoder := utilyaml.NewYAMLToJSONDecoder(file) + return loadRaw(file) +} + +func loadRaw(r io.Reader) ([]json.RawMessage, error) { + var raws []json.RawMessage + decoder := utilyaml.NewYAMLToJSONDecoder(r) for { var raw json.RawMessage - err = decoder.Decode(&raw) + err := decoder.Decode(&raw) if err != nil { if errors.Is(err, io.EOF) { break diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 370e67827..41e61feb8 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -17,9 +17,9 @@ limitations under the License. package config import ( + "bytes" "context" "encoding/json" - "os" "path/filepath" "reflect" "testing" @@ -62,7 +62,7 @@ func TestConfig(t *testing.T) { } } -func Test_loadRawConfig(t *testing.T) { +func Test_loadRaw(t *testing.T) { tests := []struct { name string data []byte @@ -142,19 +142,13 @@ kind: KwokctlConfiguration } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - p := filepath.Join(t.TempDir(), "config.yaml") - err := os.WriteFile(p, tt.data, 0640) - if err != nil { - t.Fatal(err) - } - - got, err := loadRawConfig(p) + got, err := loadRaw(bytes.NewBuffer(tt.data)) if (err != nil) != tt.wantErr { - t.Errorf("loadRawConfig() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("loadRaw() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("loadRawConfig() got = %v, want %v", got, tt.want) + t.Errorf("loadRaw() got = %v, want %v", got, tt.want) } }) } diff --git a/pkg/config/flags.go b/pkg/config/flags.go index 135045f27..067ddc06b 100644 --- a/pkg/config/flags.go +++ b/pkg/config/flags.go @@ -42,6 +42,10 @@ func InitFlags(ctx context.Context, flags *pflag.FlagSet) (context.Context, erro } configPaths := make([]string, 0, len(*config)) for _, c := range *config { + if c == "-" { + configPaths = append(configPaths, c) + continue + } configPath, err := path.Expand(c) if err != nil { return nil, err diff --git a/test/kwokctl/kwokctl-config-patches.yaml b/test/kwokctl/kwokctl-config-patches.yaml deleted file mode 100644 index 07ffc8ba2..000000000 --- a/test/kwokctl/kwokctl-config-patches.yaml +++ /dev/null @@ -1,63 +0,0 @@ -apiVersion: kwok.x-k8s.io/v1alpha1 -kind: KwokctlConfiguration -componentsPatches: - - name: kube-apiserver - extraArgs: - - key: v - value: "5" - extraVolumes: - - name: tmp-apiserver - hostPath: ./extras/apiserver - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate - - name: kube-controller-manager - extraArgs: - - key: v - value: "5" - extraVolumes: - - name: tmp-controller-manager - hostPath: ./extras/controller-manager - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate - - name: kube-scheduler - extraArgs: - - key: v - value: "5" - extraVolumes: - - name: tmp-scheduler - hostPath: ./extras/scheduler - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate - - name: kwok-controller - extraArgs: - - key: v - value: "-4" - extraVolumes: - - name: tmp-controller - hostPath: ./extras/controller - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate - - name: etcd - extraArgs: - - key: log-level - value: "debug" - extraVolumes: - - name: tmp-etcd - hostPath: ./extras/etcd - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate - - name: prometheus - extraArgs: - - key: log.level - value: "debug" - extraVolumes: - - name: tmp-prometheus - hostPath: ./extras/prometheus - mountPath: /extras/tmp - readOnly: false - pathType: DirectoryOrCreate diff --git a/test/kwokctl/kwokctl-config-runtimes.yaml b/test/kwokctl/kwokctl-config-runtimes.yaml deleted file mode 100644 index df1383cb4..000000000 --- a/test/kwokctl/kwokctl-config-runtimes.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: KwokctlConfiguration -apiVersion: kwok.x-k8s.io/v1alpha1 -options: - runtimes: - - none - - binary diff --git a/test/kwokctl/kwokctl_auto_detect.test.sh b/test/kwokctl/kwokctl_auto_detect.test.sh index a5abf6076..b29fd68d5 100755 --- a/test/kwokctl/kwokctl_auto_detect.test.sh +++ b/test/kwokctl/kwokctl_auto_detect.test.sh @@ -15,12 +15,20 @@ DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")") -source "${DIR}/helper.sh" +source "${DIR}/suite.sh" function main() { local all_releases=("${@}") for release in "${all_releases[@]}"; do - KWOK_KUBE_VERSION="${release}" kwokctl -v=-4 create cluster --timeout 30m --wait 30m --quiet-pull --config "${DIR}"/kwokctl-config-runtimes.yaml || exit 1 + name="test-kwokctl-auto-detect-${release}" + create_cluster "${name}" "${release}" --config - <