README
¶
This package includes:
- A small client interface for loading and storing kubernetes config maps, with a kube and mock implementation.
- A small wrapper client interface for loading and storing a proto struct from the contents of a config map.
Example usage:
In the service mesh hub, we use a config map to store the registries, and have a default config when the config map is not found. We can create a light wrapper around the config-to-proto client that is strongly typed for the specific proto message that the hub uses for it's config struct.
const (
ApiserverConfigKey = "config.yaml"
ApiserverConfigMapName = "apiserver-config"
DefaultLogLevel = v1.LogLevel_INFO_LEVEL
)
func GetDefaultRegistryGithubLocation() *hubv1.GithubRepositoryLocation {
return &hubv1.GithubRepositoryLocation{
Org: "solo-io",
Repo: "service-mesh-hub",
Ref: "master",
Directory: "extensions/v1",
}
}
func GetDefaultApiserverConfig() *v1.ApiserverConfig {
defaultGithub := &v1.Registry_Github{
Github: GetDefaultRegistryGithubLocation(),
}
return &v1.ApiserverConfig{
Registries: []*v1.Registry{
{
Name: "default",
RegistryType: defaultGithub,
},
},
LogLevel: DefaultLogLevel,
}
}
type ConfigClient interface {
GetConfig(ctx context.Context) (*v1.ApiserverConfig, error)
SetConfig(ctx context.Context, config *v1.ApiserverConfig) error
}
type configClient struct {
delegate configutils.ConfigClient
}
func NewConfigClient(kube configutils.ConfigMapClient, installNamespace string) ConfigClient {
delegate := configutils.NewConfigClient(kube, installNamespace, ApiserverConfigMapName, ApiserverConfigKey, GetDefaultApiserverConfig())
return &configClient{
delegate: delegate,
}
}
func (c *configClient) GetConfig(ctx context.Context) (*v1.ApiserverConfig, error) {
var config v1.ApiserverConfig
if err := c.delegate.GetConfig(ctx, &config); err != nil {
return nil, err
}
return &config, nil
}
func (c *configClient) SetConfig(ctx context.Context, config *v1.ApiserverConfig) error {
return c.delegate.SetConfig(ctx, config)
}
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrorMarshallingConfig = func(err error) error {
return errors.Wrapf(err, "could not marshal config to string")
}
ErrorUnmarshallingConfig = func(err error) error {
return errors.Wrapf(err, "could not unmarshal string to config")
}
ErrorLoadingExistingConfig = func(err error) error {
return errors.Wrapf(err, "could not load existing config")
}
ErrorUpdatingConfig = func(err error) error {
return errors.Wrapf(err, "could not update config")
}
ErrorSettingDefaultConfig = func(err error) error {
return errors.Wrapf(err, "could not get config, and could not set config to default")
}
)
Functions ¶
func ReadConfig ¶
func ReadConfig(ctx context.Context, value string, config proto.Message) error
func WriteConfigToString ¶
func WriteConfigToString(ctx context.Context, config proto.Message) (string, error)
Types ¶
type ConfigClient ¶
type ConfigClient interface {
GetConfig(ctx context.Context, config proto.Message) error
SetConfig(ctx context.Context, config proto.Message) error
}
func NewConfigClient ¶
func NewConfigClient(kube ConfigMapClient, configMapNamespace, configMapName, configKey string, defaultConfig proto.Message) ConfigClient
type ConfigMapClient ¶
type ConfigMapClient interface {
GetConfigMap(ctx context.Context, namespace string, name string) (*v1.ConfigMap, error)
SetConfigMap(ctx context.Context, config *v1.ConfigMap) error
}
func NewConfigMapClient ¶
func NewConfigMapClient(client kubernetes.Interface) ConfigMapClient
type KubeConfigMapClient ¶
type KubeConfigMapClient struct {
// contains filtered or unexported fields
}
func (*KubeConfigMapClient) GetConfigMap ¶
func (c *KubeConfigMapClient) GetConfigMap(ctx context.Context, namespace string, configMapName string) (*v1.ConfigMap, error)
func (*KubeConfigMapClient) SetConfigMap ¶
func (c *KubeConfigMapClient) SetConfigMap(ctx context.Context, config *v1.ConfigMap) error
type MockConfigMapClient ¶
type MockConfigMapClient struct {
Data map[string]string
GetError error
SetError error
}
func (*MockConfigMapClient) GetConfigMap ¶
func (c *MockConfigMapClient) GetConfigMap(ctx context.Context, namespace string, name string) (*v1.ConfigMap, error)
func (*MockConfigMapClient) SetConfigMap ¶
func (c *MockConfigMapClient) SetConfigMap(ctx context.Context, configMap *v1.ConfigMap) error
Click to show internal directories.
Click to hide internal directories.