-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add secret and configmap generator plugins
- Loading branch information
1 parent
e7be999
commit 18f6328
Showing
12 changed files
with
325 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
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 plugin | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"plugin" | ||
) | ||
|
||
var _ Factory = &goFactory{} | ||
|
||
const ( | ||
dir = "$HOME/.config/kustomize/plugins/kvsource" | ||
) | ||
|
||
func newGoFactory() *goFactory { | ||
return &goFactory{ | ||
plugins: make(map[string]KVSource), | ||
} | ||
} | ||
|
||
type goFactory struct { | ||
plugins map[string]KVSource | ||
} | ||
|
||
func (p *goFactory) load(name string) (KVSource, error) { | ||
if plug, ok := p.plugins[name]; ok { | ||
return plug, nil | ||
} | ||
|
||
goPlugin, err := plugin.Open(fmt.Sprintf("%s/kustomize-%s.so", os.ExpandEnv(dir), name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
symbol, err := goPlugin.Lookup("Plugin") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
plug, ok := symbol.(KVSource) | ||
if !ok { | ||
return nil, fmt.Errorf("plugin %s not found", name) | ||
} | ||
|
||
p.plugins[name] = plug | ||
return plug, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
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 plugin provides a plugin abstraction layer. | ||
package plugin | ||
|
||
import ( | ||
"sigs.k8s.io/kustomize/k8sdeps/kv" | ||
) | ||
|
||
// KVSource is the interface for kv source plugins. | ||
type KVSource interface { | ||
Get(root string, args []string) ([]kv.Pair, error) | ||
} | ||
|
||
// Factory is the interface for new kv source plugin implementations. | ||
type Factory interface { | ||
load(string) (KVSource, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
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 plugin | ||
|
||
import ( | ||
"fmt" | ||
|
||
"sigs.k8s.io/kustomize/pkg/ifc" | ||
) | ||
|
||
// Registry holds all the plugin factories. | ||
type Registry struct { | ||
factories map[string]Factory | ||
ldr ifc.Loader | ||
} | ||
|
||
// NewRegistry returns a new Registry loaded with all the factories. | ||
func NewRegistry(ldr ifc.Loader) Registry { | ||
return Registry{ | ||
ldr: ldr, | ||
factories: map[string]Factory{ | ||
"go": newGoFactory(), | ||
"testonly": newTestonlyFactory(), | ||
}, | ||
} | ||
} | ||
|
||
// Load returns a plugin by type and name, | ||
func (r *Registry) Load(pluginType, name string) (KVSource, error) { | ||
factory, exists := r.factories[pluginType] | ||
if !exists { | ||
return nil, fmt.Errorf("%s is not a valid plugin type", pluginType) | ||
} | ||
return factory.load(name) | ||
} | ||
|
||
// Root returns the root of the plugins kustomization file. | ||
func (r *Registry) Root() string { | ||
return r.ldr.Root() | ||
} |
Oops, something went wrong.