Skip to content

Commit 093df10

Browse files
authored
Merge pull request #32 from jaypipes/set-defaults
support api.DefaultsHandler
2 parents d8f2f14 + 87107f4 commit 093df10

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

defaults.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,39 @@ type kubeDefaults struct {
3232
Namespace string `yaml:"namespace,omitempty"`
3333
}
3434

35-
// Defaults is the known HTTP plugin defaults collection
35+
// Defaults is the known kube plugin defaults collection
3636
type Defaults struct {
3737
kubeDefaults
3838
}
3939

40+
// Merge merges the supplies map of key/value combinations with the set of
41+
// handled defaults for the plugin. The supplied key/value map will NOT be
42+
// unpacked from its top-most plugin named element. So, for example, the
43+
// kube plugin should expect to get a map that looks like
44+
// "kube:namespace:<namespace>" and not "namespace:<namespace>".
45+
func (d *Defaults) Merge(vals map[string]any) {
46+
kubeValsAny, ok := vals[pluginName]
47+
if !ok {
48+
return
49+
}
50+
kubeVals, ok := kubeValsAny.(map[string]string)
51+
if !ok {
52+
return
53+
}
54+
cfg, ok := kubeVals["config"]
55+
if ok {
56+
d.Config = cfg
57+
}
58+
ctx, ok := kubeVals["context"]
59+
if ok {
60+
d.Context = ctx
61+
}
62+
ns, ok := kubeVals["namespace"]
63+
if ok {
64+
d.Namespace = ns
65+
}
66+
}
67+
4068
func (d *Defaults) UnmarshalYAML(node *yaml.Node) error {
4169
if node.Kind != yaml.MappingNode {
4270
return parse.ExpectedMapAt(node)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.3
44

55
require (
66
github.com/cenkalti/backoff v2.2.1+incompatible
7-
github.com/gdt-dev/core v1.10.5
7+
github.com/gdt-dev/core v1.11.0
88
github.com/samber/lo v1.51.0
99
github.com/stretchr/testify v1.11.1
1010
github.com/theory/jsonpath v0.10.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjT
1919
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
2020
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
2121
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
22-
github.com/gdt-dev/core v1.10.5 h1:plVO6WegOEuJTopnmTRQTIwyvHY2iG4xXDax2OP4fO8=
23-
github.com/gdt-dev/core v1.10.5/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
22+
github.com/gdt-dev/core v1.11.0 h1:jEKDMZ8eoQIQMlTB2C6Ai6q7CfgHJ3y9MVFSzdgc208=
23+
github.com/gdt-dev/core v1.11.0/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
2424
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
2525
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
2626
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=

plugin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package kube
77
import (
88
"github.com/gdt-dev/core/api"
99
gdtplugin "github.com/gdt-dev/core/plugin"
10-
"gopkg.in/yaml.v3"
1110
)
1211

1312
var (
@@ -39,7 +38,7 @@ func (p *plugin) Info() api.PluginInfo {
3938
}
4039
}
4140

42-
func (p *plugin) Defaults() yaml.Unmarshaler {
41+
func (p *plugin) Defaults() api.DefaultsHandler {
4342
return &Defaults{}
4443
}
4544

0 commit comments

Comments
 (0)