From f6bd4e9336e35d136d9a4c7d93949ec89a650c29 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Fri, 15 May 2020 21:38:05 +0200 Subject: [PATCH 01/18] wip v0.1.0 --- components/network.go | 149 +++++++++------ components/settings.go | 68 ------- components/workload.go | 51 ++--- components/zz_generated.deepcopy.go | 61 +++--- instance/component.go | 41 +--- instance/instance.go | 212 ++++++++++++++++++--- instance/object.go | 19 +- instance/settings.go | 74 ++----- meta/instance.go | 78 ++++++++ meta/meta.go | 51 +++++ meta/mutate.go | 84 -------- meta/object.go | 34 ++-- meta/zz_generated.deepcopy.go | 7 - objects/container/object.go | 11 +- objects/container/zz_generated.deepcopy.go | 5 +- objects/ingress/object.go | 3 - objects/service/object.go | 9 - settings/env.go | 127 ++++++++++++ settings/interface.go | 43 ++--- settings/parameter.go | 18 +- settings/parameter_helper.go | 4 + settings/parameters_helpers.go | 104 +--------- settings/settings.go | 196 ++----------------- settings/utils.go | 101 ++++++++++ settings/zz_generated.deepcopy.go | 41 ---- utils/utils.go | 13 ++ 26 files changed, 779 insertions(+), 825 deletions(-) delete mode 100644 components/settings.go create mode 100644 meta/instance.go create mode 100644 meta/meta.go delete mode 100644 meta/mutate.go create mode 100644 settings/env.go create mode 100644 settings/utils.go create mode 100644 utils/utils.go diff --git a/components/network.go b/components/network.go index 1a1a238..669cd5f 100644 --- a/components/network.go +++ b/components/network.go @@ -23,73 +23,90 @@ import ( networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/util/intstr" + "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" ingress "k8s.libre.sh/objects/ingress" service "k8s.libre.sh/objects/service" ) -// +kubebuilder:object:generate=true -type Network struct { +type Serv struct { *meta.ObjectMeta `json:"commonMeta,omitempty"` - Service Service `json:"service,omitempty"` - Ingress Ingress `json:"ingress,omitempty"` + *Backend `json:"backend,omitempty"` } -// +kubebuilder:object:generate=true -type Service struct { - *meta.ObjectMeta `json:"meta,omitempty"` - Port service.Port `json:"port,omitempty"` - Type corev1.ServiceType `json:"type,omitempty"` +func (s *Serv) Mutate(obj interfaces.Object) error { + service.MutateService(s, obj.(*corev1.Service), s.ObjectMeta) + meta.MutateMeta(s, obj) + return nil +} + +func (s *Serv) GetObject() interfaces.Object { + return &corev1.Service{} +} + +type Ing struct { + *meta.ObjectMeta `json:"commonMeta,omitempty"` + Backends []Backend `json:"backends,omitempty"` } // +kubebuilder:object:generate=true -type Ingress struct { - *meta.ObjectMeta `json:"meta,omitempty"` - Host string `json:"host,omitempty"` - Paths []string `json:"routes,omitempty"` - TLS bool `json:"tls,omitempty"` - TLSSecretRef string `json:"tlsSecretRef,omitempty"` +type Backend struct { + ServiceName string `json:"name,omitempty"` + Hostname string `json:"hostname,omitempty"` + Paths []string `json:"routes,omitempty"` + TLS bool `json:"tls,omitempty"` + TLSSecretRef string `json:"tlsSecretRef,omitempty"` + Port service.Port `json:"port,omitempty"` + ServiceType corev1.ServiceType `json:"type,omitempty"` } -func (r *Network) GetIngress() *ingress.Ingress { - ing := &ingress.Ingress{ - ObjectMeta: r.Ingress.ObjectMeta, - IngressSpec: &networkingv1beta1.IngressSpec{ - Rules: r.GetIngressRules(), - TLS: r.GetIngressTLS(), - }, - } - return ing +func (i *Ing) Mutate(obj interfaces.Object) error { + // o.Service.Meta = o.Meta + ingress.MutateIngress(i, obj.(*networkingv1beta1.Ingress)) + meta.MutateMeta(i, obj) + return nil } -func (c *Network) GetService() *service.Service { - svc := &service.Service{ - ObjectMeta: c.Service.ObjectMeta, - ServiceSpec: &service.ServiceSpec{ - Ports: []service.Port{ - c.Service.Port, - }, - Type: c.Service.Type, - }, - } +func (i *Ing) GetObject() interfaces.Object { + return &networkingv1beta1.Ingress{} +} + +func (b *Backend) GetServiceType() corev1.ServiceType { return b.ServiceType } + +func (b *Backend) GetServicePorts() []corev1.ServicePort { + + ports := []corev1.ServicePort{} + ports = append(ports, b.GetServicePort()) - return svc + return ports } -func (r *Network) GetIngressAnnotations() map[string]string { - return r.Ingress.ObjectMeta.Annotations +func (b *Backend) GetServicePort() corev1.ServicePort { + + port := corev1.ServicePort{ + TargetPort: intstr.FromString(b.Port.Name), + Port: b.Port.Port, + Name: b.Port.Name, + } + + if len(b.Port.Protocol) > 0 { + port.Protocol = b.Port.Protocol + } + + return port } -func (r *Network) GetIngressBackendPaths() []networkingv1beta1.HTTPIngressPath { +func (b *Backend) GetIngressBackendPaths() []networkingv1beta1.HTTPIngressPath { bkpaths := []networkingv1beta1.HTTPIngressPath{} - for _, p := range r.Ingress.Paths { + for _, p := range b.Paths { path := networkingv1beta1.HTTPIngressPath{ Path: p, Backend: networkingv1beta1.IngressBackend{ - ServiceName: r.Service.ObjectMeta.Name, - ServicePort: intstr.FromString(r.Service.Port.Name), + // TODO TO FIX + ServiceName: b.ServiceName, + ServicePort: intstr.FromString(b.Port.Name), }, } @@ -98,40 +115,54 @@ func (r *Network) GetIngressBackendPaths() []networkingv1beta1.HTTPIngressPath { return bkpaths } -func (r *Network) GetIngressRules() []networkingv1beta1.IngressRule { - - rules := []networkingv1beta1.IngressRule{} +func (b *Backend) GetIngressRule() networkingv1beta1.IngressRule { rule := networkingv1beta1.IngressRule{ - Host: r.Ingress.Host, + Host: b.Hostname, IngressRuleValue: networkingv1beta1.IngressRuleValue{ HTTP: &networkingv1beta1.HTTPIngressRuleValue{ - Paths: r.GetIngressBackendPaths(), + Paths: b.GetIngressBackendPaths(), }, }, } - rules = append(rules, rule) + return rule +} + +func (i *Ing) GetIngressRules() []networkingv1beta1.IngressRule { + + rules := []networkingv1beta1.IngressRule{} + + for _, ing := range i.Backends { + rules = append(rules, ing.GetIngressRule()) + } return rules } -func (r *Network) GetIngressTLS() []networkingv1beta1.IngressTLS { - +func (b *Backend) GetIngressTLS() networkingv1beta1.IngressTLS { tls := networkingv1beta1.IngressTLS{} - tlsList := []networkingv1beta1.IngressTLS{} - - if &r.Ingress.TLS != nil { - if len(r.Ingress.TLSSecretRef) == 0 { - r.Ingress.TLSSecretRef = fmt.Sprintf("%v-%v", strings.Replace(r.Ingress.Host, ".", "-", -1), "tls") + if b.TLS { + if len(b.TLSSecretRef) == 0 { + b.TLSSecretRef = fmt.Sprintf("%v-%v", strings.Replace(b.Hostname, ".", "-", -1), "tls") } + tls = networkingv1beta1.IngressTLS{ - SecretName: r.Ingress.TLSSecretRef, + SecretName: b.TLSSecretRef, } - tls.Hosts = append(tls.Hosts, r.Ingress.Host) - tlsList = append(tlsList, tls) - } else { - tlsList = nil + + tls.Hosts = append(tls.Hosts, b.Hostname) + } + return tls +} + +func (i *Ing) GetIngressTLS() []networkingv1beta1.IngressTLS { + + tlsList := []networkingv1beta1.IngressTLS{} + + for _, ing := range i.Backends { + tlsList = append(tlsList, ing.GetIngressTLS()) } + return tlsList } diff --git a/components/settings.go b/components/settings.go deleted file mode 100644 index ff41ea5..0000000 --- a/components/settings.go +++ /dev/null @@ -1,68 +0,0 @@ -package components - -/* -// +kubebuilder:object:generate=true -type Settings struct { - *meta.ObjectMeta `json:"meta,omitempty"` - parameters.Parameters `json:"parameters,omitempty"` -} - -func (s *Settings) GetParameters() *parameters.Parameters { - return &s.Parameters -} - -func (s *Settings) GetObjects() []instance.Object { - objects := []instance.Object{} - - // for _, param := range *s.Parameters { - // if len(param.Value) > 0 && len(param.Key) > 0 { - // if param.Type == "Secret" { - // objects = append(objects, secret) - // } - // objects = append(objects, secret) - // } - // } - return objects - -} - -func (s *Settings) GetConfigRefs() []string { return nil } - -func (s *Settings) GetSecretRefs() []string { return nil } - -func (s *Settings) SetDefaults(i instance.Instance) { - - if s.ObjectMeta == nil { - s.ObjectMeta = new(meta.ObjectMeta) - } - - if len(s.ObjectMeta.Labels) == 0 { - s.ObjectMeta.Labels = make(map[string]string) - } - - instanceLabels := instance.InstanceLabels(i) - - s.ObjectMeta.SetLabels(instanceLabels) - s.ObjectMeta.Labels["app.kubernetes.io/component"] = "settings" - - if len(s.ObjectMeta.Name) == 0 { - s.ObjectMeta.Name = fmt.Sprintf("%v-%v", i.GetName(), "settings") - } - - if len(s.ObjectMeta.Namespace) == 0 { - s.ObjectMeta.Namespace = i.GetNamespace() - } - -} - -func CreateAndInitSettings(i instance.Settings) *Settings { - return &Settings{ - ObjectMeta: &meta.ObjectMeta{ - Name: i.GetMeta().GetName(), - Namespace: i.GetMeta().GetNamespace(), - Labels: instance.InstanceLabels(i.GetMeta()), - }, - Parameters: *i.GetParameters().Parameters, - } -} -*/ diff --git a/components/workload.go b/components/workload.go index eda98b0..4f372e6 100644 --- a/components/workload.go +++ b/components/workload.go @@ -24,10 +24,9 @@ import ( // +kubebuilder:object:generate=true type Workload struct { - *meta.ObjectMeta `json:"commonMeta,omitempty"` - //*Settings `json:"settings,omitempty"` + *meta.ObjectMeta `json:"commonMeta,omitempty"` *deployment.Deployment `json:"deployment,omitempty"` - *Network `json:"network,omitempty"` + *Backend `json:"network,omitempty"` Dependencies bool `json:"dependencies,omitempty"` } @@ -35,7 +34,7 @@ func (w *Workload) HasDependencies() bool { return w.Dependencies } -func (w *Workload) GetMeta() instance.Meta { +func (w *Workload) GetMeta() meta.Instance { return w.ObjectMeta } @@ -43,24 +42,37 @@ func (w *Workload) GetObjects() map[int]instance.Object { objects := make(map[int]instance.Object) - objects[0] = w.Network.GetService() - objects[1] = w.Network.GetIngress() + ing := &Ing{ + ObjectMeta: &meta.ObjectMeta{}, + Backends: []Backend{ + *w.Backend, + }, + } + srv := &Serv{ + ObjectMeta: &meta.ObjectMeta{}, + Backend: w.Backend, + } + + objects[0] = srv + objects[1] = ing objects[2] = w.Deployment return objects } -func (w *Workload) SetDependencies(s *parameters.Settings) { w.Settings = *s } -func (w *Workload) GetDependencies() parameters.Interface { return &w.Settings } +func (w *Workload) SetDependencies(s *parameters.Settings) { w.EnvSpec = s.EnvSpec } +func (w *Workload) GetDependencies() parameters.Env { return w.EnvSpec } -// TODO make a generic function with component interface -// getObjects loop setObjectMetaFromComponent -// merge labels && annotations && finalizers not set -func (w *Workload) SetDefaults(i instance.Instance) { +func (w *Workload) SetDefaults() { // TODO FIXME w.Dependencies = true + w.Backend.ServiceName = w.GetName() +} + +func (w *Workload) Init() { + // TODO improve initialisation of objectMeta, labels... if w.ObjectMeta == nil { w.ObjectMeta = new(meta.ObjectMeta) @@ -70,24 +82,19 @@ func (w *Workload) SetDefaults(i instance.Instance) { w.ObjectMeta.Labels = make(map[string]string) } - // TODO TOFIX + // TODO FIXME w.ObjectMeta.SetComponent("app") if w.Deployment.ObjectMeta == nil { w.Deployment.ObjectMeta = new(meta.ObjectMeta) } - if w.Network.ObjectMeta == nil { - w.Network.ObjectMeta = new(meta.ObjectMeta) - } - - if w.Network.Ingress.ObjectMeta == nil { - w.Network.Ingress.ObjectMeta = new(meta.ObjectMeta) + if w.EnvSpec == nil { + w.EnvSpec = new(parameters.EnvSpec) } - if w.Network.Service.ObjectMeta == nil { - w.Network.Service.ObjectMeta = new(meta.ObjectMeta) + if w.Backend == nil { + w.Backend = &Backend{} } - instance.InitComponent(i, w) } diff --git a/components/zz_generated.deepcopy.go b/components/zz_generated.deepcopy.go index 32b6e11..6b5487f 100644 --- a/components/zz_generated.deepcopy.go +++ b/components/zz_generated.deepcopy.go @@ -25,69 +25,56 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Ingress) DeepCopyInto(out *Ingress) { +func (in *Backend) DeepCopyInto(out *Backend) { *out = *in - if in.ObjectMeta != nil { - in, out := &in.ObjectMeta, &out.ObjectMeta - *out = new(meta.ObjectMeta) - (*in).DeepCopyInto(*out) - } if in.Paths != nil { in, out := &in.Paths, &out.Paths *out = make([]string, len(*in)) copy(*out, *in) } + out.Port = in.Port } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Ingress. -func (in *Ingress) DeepCopy() *Ingress { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Backend. +func (in *Backend) DeepCopy() *Backend { if in == nil { return nil } - out := new(Ingress) + out := new(Backend) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Network) DeepCopyInto(out *Network) { +func (in *Settings) DeepCopyInto(out *Settings) { *out = *in - if in.ObjectMeta != nil { - in, out := &in.ObjectMeta, &out.ObjectMeta + if in.CommonMeta != nil { + in, out := &in.CommonMeta, &out.CommonMeta *out = new(meta.ObjectMeta) (*in).DeepCopyInto(*out) } - in.Service.DeepCopyInto(&out.Service) - in.Ingress.DeepCopyInto(&out.Ingress) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Network. -func (in *Network) DeepCopy() *Network { - if in == nil { - return nil + if in.SecretMeta != nil { + in, out := &in.SecretMeta, &out.SecretMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) } - out := new(Network) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Service) DeepCopyInto(out *Service) { - *out = *in - if in.ObjectMeta != nil { - in, out := &in.ObjectMeta, &out.ObjectMeta + if in.ConfigMeta != nil { + in, out := &in.ConfigMeta, &out.ConfigMeta *out = new(meta.ObjectMeta) (*in).DeepCopyInto(*out) } - out.Port = in.Port + if in.EnvSpec != nil { + in, out := &in.EnvSpec, &out.EnvSpec + *out = (*in).DeepCopy() + } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Service. -func (in *Service) DeepCopy() *Service { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. +func (in *Settings) DeepCopy() *Settings { if in == nil { return nil } - out := new(Service) + out := new(Settings) in.DeepCopyInto(out) return out } @@ -105,9 +92,9 @@ func (in *Workload) DeepCopyInto(out *Workload) { *out = new(deployment.Deployment) (*in).DeepCopyInto(*out) } - if in.Network != nil { - in, out := &in.Network, &out.Network - *out = new(Network) + if in.Backend != nil { + in, out := &in.Backend, &out.Backend + *out = new(Backend) (*in).DeepCopyInto(*out) } } diff --git a/instance/component.go b/instance/component.go index 3e84a68..fabf2cb 100644 --- a/instance/component.go +++ b/instance/component.go @@ -3,16 +3,18 @@ package instance import ( "github.com/presslabs/controller-util/syncer" interfaces "k8s.libre.sh/interfaces" + meta "k8s.libre.sh/meta" parameters "k8s.libre.sh/settings" ) type Component interface { - Meta - GetMeta() Meta - SetDefaults(i Instance) + meta.Instance + GetMeta() meta.Instance + SetDefaults() + Init() GetObjects() map[int]Object HasDependencies() bool - GetDependencies() parameters.Interface + GetDependencies() parameters.Env // SetDependencies(*parameters.Settings) } @@ -30,41 +32,14 @@ func InitComponent(i Instance, c Component) { component := c.GetComponent() - SetObjectMeta(i, c) + meta.SetObjectMeta(i, c) if len(component) > 0 { c.SetComponent(component) } for _, o := range c.GetObjects() { - SetObjectMeta(c, o) + meta.SetObjectMeta(c, o) } - if c.HasDependencies() { - dependencies := i.GetSettings().GetParameters() - - settings := c.GetDependencies() - - settings = parameters.MergeSettings(dependencies, settings) - - } -} - -func MergeSettings(dependencies, settings *parameters.Settings) *parameters.Settings { - params := parameters.Parameters{} - - if settings == nil { - settings = dependencies - } else { - - settings.SetConfigRefs(append(settings.GetConfigRefs(), dependencies.GetConfigRefs()...)) - settings.SetSecretRefs(append(settings.GetSecretRefs(), dependencies.GetSecretRefs()...)) - - for _, p := range *dependencies.GetParameters() { - params = append(params, p) - settings.Parameters = ¶ms - } - } - - return settings } diff --git a/instance/instance.go b/instance/instance.go index 0dea0e7..905a661 100644 --- a/instance/instance.go +++ b/instance/instance.go @@ -1,55 +1,211 @@ package instance import ( + "context" + "github.com/presslabs/controller-util/syncer" - "k8s.io/apimachinery/pkg/labels" interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" + parameters "k8s.libre.sh/settings" + "sigs.k8s.io/controller-runtime/pkg/client" + + corev1 "k8s.io/api/core/v1" ) type Instance interface { - Meta + meta.Instance GetComponents() map[int]Component GetOwner() interfaces.Object GetSettings() Settings + SetDefaults() } -type Meta interface { - meta.Meta - GetApplication() string - SetApplication(string) - GetInstance() string - SetInstance(string) - GetVersion() string - SetVersion(string) - GetComponent() string - SetComponent(string) - GetPartOf() string - SetPartOf(string) - GetManagedBy() string - SetManagedBy(string) -} +func Init(i Instance) { + + i.SetDefaults() + + for _, c := range i.GetComponents() { + c.Init() + + // TODO TOFIX + component := c.GetComponent() + + meta.SetObjectMeta(i, c) + + if len(component) > 0 { + c.SetComponent(component) + } + + for _, o := range c.GetObjects() { + meta.SetObjectMeta(c, o) + } + + c.SetDefaults() -func InstanceLabels(m Meta) map[string]string { - labels := labels.Set{ - "app.kubernetes.io/name": m.GetApplication(), - "app.kubernetes.io/instance": m.GetInstance(), - "app.kubernetes.io/version": m.GetVersion(), - "app.kubernetes.io/component": m.GetComponent(), - "app.kubernetes.io/part-of": m.GetPartOf(), - "app.kubernetes.io/managed-by": m.GetManagedBy(), } - return labels + } -func NewSyncers(i Instance, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface) { - components := i.GetComponents() +func NewSyncers(app Instance, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface) { + + ///////////////////// + //// Settings ////// + /////////////////// + + // INITIALISE VALUES FROM EXTERNAL RESOURCES, RANDOM & TEMPLATES + sett := app.GetSettings().GetEnv().(*parameters.Settings) + + err := InitParametersValueFrom(sett, app.GetSettings().GetMeta(), r) + + if err != nil { + // return ctrl.Result{}, err + } + + sett.InitRandValues() + err = sett.InitTemplateValues(parameters.KeyPairValues(sett.Parameters)) + + if err != nil { + // return nil, err + } + + // Object Syncers + objects := GetObjects(sett) + + for _, obj := range objects { + s := NewObjectSyncer(obj, owner, r) + + if err := syncer.Sync(context.TODO(), s, r.GetRecorder()); err != nil { + // return nil, err + } + + } + + ///////////////////// + //// Components //// + /////////////////// + components := app.GetComponents() + + // INITIALIZE for _, c := range components { + + component := c.GetComponent() + + meta.SetObjectMeta(app, c) + + if len(component) > 0 { + c.SetComponent(component) + } + + if c.HasDependencies() { + + settings := c.GetDependencies() + settings = parameters.MergeSettings(sett, settings) + + } + // GET SYNCERS mutators := c.GetObjects() for _, m := range mutators { + meta.SetObjectMeta(c, m) syncers = append(syncers, NewObjectSyncer(m, owner, r)) } } return syncers + +} + +func GetAndMergeParameters(params parameters.Parameters, paramsByKey map[string]*parameters.Parameter, r interfaces.Reconcile, obj interfaces.Object) error { + + objectKey, _ := client.ObjectKeyFromObject(obj) + + err := r.GetClient().Get(context.Background(), objectKey, obj) + + if err != nil { + return err + } + + data := map[string]string{} + + if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { + for k, v := range obj.(*corev1.Secret).Data { + data[k] = string(v) + } + } + if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { + for k, v := range obj.(*corev1.ConfigMap).Data { + data[k] = v + } + } + + if len(params) > 0 { + for _, pp := range params { + paramsByKey[pp.Key].Value = string(data[pp.FromKey]) + } + } else { + for kk, vv := range data { + if paramsByKey[kk] == nil { + paramsByKey[kk] = new(parameters.Parameter) + } + paramsByKey[kk].Value = vv + paramsByKey[kk].Key = kk + // TODO This would be checked if we want to recreate the data or juste mount the whole secret + paramsByKey[kk].MountType = parameters.MountEnvFile + } + } + + return nil +} + +// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace +// All parameters values are filled from those resources +func InitParametersValueFrom(s *parameters.Settings, m meta.Meta, r interfaces.Reconcile) error { + // params := s.GetParameters().(*parameters.Settings) + + params := parameters.Parameters{} + + paramsByKey := parameters.ParametersByKey(s.Parameters) + paramsBySecretSource, paramsByConfigMapSource := parameters.OrderByResourceRef(s) + + cm := &corev1.ConfigMap{} + sec := &corev1.Secret{} + + cm.SetNamespace(m.GetNamespace()) + sec.SetNamespace(m.GetNamespace()) + + // We get the secrets + for k, v := range paramsBySecretSource { + sec.SetName(k) + + err := GetAndMergeParameters(v, paramsByKey, r, sec) + if err != nil { + return err + } + } + + for k, v := range paramsByConfigMapSource { + cm.SetName(k) + err := GetAndMergeParameters(v, paramsByKey, r, sec) + if err != nil { + return err + } + } + + for _, v := range paramsByKey { + if v.MountType == parameters.MountEnvFile { + if v.Type == parameters.ConfigParameter { + v.Ref = s.GetConfigMapMeta().GetName() + } + if v.Type == parameters.SecretParameter { + v.Ref = s.GetSecretMeta().GetName() + } + } + params = append(params, v) + } + + // TODO FIX THIS we need to check if we want to mount as EnvFile and reset old resources references + s.SecretRefs = []string{} + s.ConfigRefs = []string{} + s.Parameters = ¶ms + + return nil } diff --git a/instance/object.go b/instance/object.go index 5f3ec28..3a5fd59 100644 --- a/instance/object.go +++ b/instance/object.go @@ -16,33 +16,18 @@ limitations under the License. package instance import ( - "fmt" - - "k8s.io/apimachinery/pkg/labels" interfaces "k8s.libre.sh/interfaces" + meta "k8s.libre.sh/meta" "github.com/presslabs/controller-util/syncer" ) type Object interface { - Meta + meta.Instance Mutate(obj interfaces.Object) error GetObject() interfaces.Object } -func SetObjectMeta(instance Meta, dest Meta) { - - dest.SetLabels(labels.Merge(dest.GetLabels(), InstanceLabels(instance))) - - if len(dest.GetName()) == 0 { - dest.SetName(fmt.Sprintf("%v-%v", instance.GetInstance(), dest.GetComponent())) - } - if len(dest.GetNamespace()) == 0 { - dest.SetNamespace(instance.GetNamespace()) - - } -} - func NewObjectSyncer(i Object, owner interfaces.Object, r interfaces.Reconcile) syncer.Interface { obj := i.GetObject() obj.SetName(i.GetName()) diff --git a/instance/settings.go b/instance/settings.go index 94ed3a9..84b4068 100644 --- a/instance/settings.go +++ b/instance/settings.go @@ -22,61 +22,12 @@ import ( parameters "k8s.libre.sh/settings" ) -type Dependency interface { - GetParameters() parameters.Interface - // GetSecretParameters() *parameters.Settings - // GetConfigParameters() *parameters.Settings - SetDefaults(i Instance) -} - type Settings interface { - GetMeta() Meta - GetSecretMeta() Meta - GetConfigMapMeta() Meta - GetParameters() parameters.Interface - // GetSecretParameters() *parameters.Settings - // GetConfigParameters() *parameters.Settings - // GetSecret() secret.Mutate - // GetConfigMap() configmap.Mutate - SetDefaults(i Instance) -} - -func InitParametersFromSettings(s Settings, p parameters.Interface) { - - secretRefs := p.GetSecretRefs() - configRefs := p.GetConfigRefs() - - for _, param := range *p.GetParameters() { - if len(param.MountType) == 0 { - param.MountType = parameters.MountFrom - - if len(param.ValueFrom.Ref) == 0 { - if param.Type == parameters.SecretParameter { - secretRefs = append(secretRefs, s.GetMeta().GetName()) - } - configRefs = append(configRefs, s.GetMeta().GetName()) - } - } - - if len(param.Type) == 0 { - param.Type = parameters.ConfigParameter - } - } - - p.SetConfigRefs(Unique(configRefs)) - p.SetSecretRefs(Unique(secretRefs)) -} - -func Unique(stringSlice []string) []string { - keys := make(map[string]bool) - list := []string{} - for _, entry := range stringSlice { - if _, value := keys[entry]; !value { - keys[entry] = true - list = append(list, entry) - } - } - return list + GetMeta() meta.Instance + GetSecretMeta() meta.Instance + GetConfigMapMeta() meta.Instance + GetEnv() parameters.Env + SetDefaults() } func GetObjects(s Settings) map[int]Object { @@ -91,25 +42,28 @@ func GetObjects(s Settings) map[int]Object { objs := make(map[int]Object, 2) - SetObjectMeta(s.GetMeta(), cm.ObjectMeta) - SetObjectMeta(s.GetMeta(), secret.ObjectMeta) + meta.SetObjectMeta(s.GetConfigMapMeta(), cm.ObjectMeta) + meta.SetObjectMeta(s.GetSecretMeta(), secret.ObjectMeta) // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS - params := s.GetParameters() + params := s.GetEnv() for _, p := range *params.GetParameters() { // TODO check not mountLiteral ?? - if p.Type == parameters.SecretParameter && len(p.Value) > 0 { + if p.MountType == parameters.MountEnvFile && + p.Type == parameters.SecretParameter && + len(p.Value) > 0 { secret.Parameters = append(secret.Parameters, p) } - if p.Type == parameters.ConfigParameter && len(p.Value) > 0 { + if p.MountType == parameters.MountEnvFile && + p.Type == parameters.ConfigParameter && + len(p.Value) > 0 { cm.Parameters = append(cm.Parameters, p) } } // TODO IMPROVE if len(cm.Parameters) > 0 { - // cm.Parameters = cmParameters objs[0] = cm } diff --git a/meta/instance.go b/meta/instance.go new file mode 100644 index 0000000..594c05b --- /dev/null +++ b/meta/instance.go @@ -0,0 +1,78 @@ +/* + +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 meta + +import ( + "fmt" + + "k8s.io/apimachinery/pkg/labels" +) + +type Instance interface { + Meta + GetApplication() string + SetApplication(string) + GetInstance() string + SetInstance(string) + GetVersion() string + SetVersion(string) + GetComponent() string + SetComponent(string) + GetPartOf() string + SetPartOf(string) + GetManagedBy() string + SetManagedBy(string) +} + +/* type Application interface { + GetApplication() string + SetApplication(string) + GetInstance() string + SetInstance(string) + GetVersion() string + SetVersion(string) + GetComponent() string + SetComponent(string) + GetPartOf() string + SetPartOf(string) + GetManagedBy() string + SetManagedBy(string) +} */ + +func InstanceLabels(m Instance) map[string]string { + labels := labels.Set{ + "app.kubernetes.io/name": m.GetApplication(), + "app.kubernetes.io/instance": m.GetInstance(), + "app.kubernetes.io/version": m.GetVersion(), + "app.kubernetes.io/component": m.GetComponent(), + "app.kubernetes.io/part-of": m.GetPartOf(), + "app.kubernetes.io/managed-by": m.GetManagedBy(), + } + return labels +} + +func SetObjectMeta(src Instance, dest Instance) { + + dest.SetLabels(labels.Merge(dest.GetLabels(), InstanceLabels(src))) + + if len(dest.GetName()) == 0 { + dest.SetName(fmt.Sprintf("%v-%v", src.GetInstance(), dest.GetComponent())) + } + if len(dest.GetNamespace()) == 0 { + dest.SetNamespace(src.GetNamespace()) + + } +} diff --git a/meta/meta.go b/meta/meta.go new file mode 100644 index 0000000..c487da9 --- /dev/null +++ b/meta/meta.go @@ -0,0 +1,51 @@ +/* + +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 meta + +import ( + "k8s.io/apimachinery/pkg/labels" + interfaces "k8s.libre.sh/interfaces" +) + +type Meta interface { + GetLabels() map[string]string + SetLabels(labels map[string]string) + GetAnnotations() map[string]string + SetAnnotations(annotations map[string]string) + GetName() string + SetName(string) + GetNamespace() string + SetNamespace(string) +} + +func MutateMeta(o Meta, obj interfaces.Object) error { + obj.SetLabels(o.GetLabels()) + + if len(o.GetAnnotations()) > 0 { + obj.SetAnnotations(labels.Merge(obj.GetAnnotations(), o.GetAnnotations())) + } + + // if len(obj.GetName()) == 0 { + // obj.SetName(o.GetName()) + + // } + + // if len(obj.GetNamespace()) == 0 { + // obj.SetNamespace(o.GetNamespace()) + // } + + return nil +} diff --git a/meta/mutate.go b/meta/mutate.go deleted file mode 100644 index 5fb0856..0000000 --- a/meta/mutate.go +++ /dev/null @@ -1,84 +0,0 @@ -/* - -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 meta - -import ( - interfaces "k8s.libre.sh/interfaces" -) - -type Meta interface { - GetLabels() map[string]string - SetLabels(labels map[string]string) - GetName() string - SetName(string) - GetNamespace() string - SetNamespace(string) -} - -type Labels map[string]string - -/* func (l *Labels) GetApplication() string { return *l["app.kubernetes.io/name"] } - -func (l *Labels) SetApplication(s string) { *l["app.kubernetes.io/name"] = s } - -func (l *Labels) GetInstance() string { return *l["app.kubernetes.io/instance"] } - -func (l *Labels) SetInstance(s string) { *l["app.kubernetes.io/instance"] = s } - -func (l *Labels) GetVersion() string { return *l["app.kubernetes.io/version"] } - -func (l *Labels) SetVersion(s string) { *l["app.kubernetes.io/version"] = s } - -func (l *Labels) GetComponent() string { return *l["app.kubernetes.io/component"] } - -func (l *Labels) SetComponent(s string) { *l["app.kubernetes.io/component"] = s } - -func (l *Labels) GetPartOf() string { return *l["app.kubernetes.io/part-of"] } - -func (l *Labels) SetPartOf(s string) { *l["app.kubernetes.io/part-of"] = s } - -func (l *Labels) GetManagedBy() string { *l["app.kubernetes.io/managed-by"] } - -func (l *Labels) SetManagedBy(s string) { *l["app.kubernetes.io/managed-by"] = s } -*/ -type Application interface { - GetApplication() string - SetApplication(string) - GetInstance() string - SetInstance(string) - GetVersion() string - SetVersion(string) - GetComponent() string - SetComponent(string) - GetPartOf() string - SetPartOf(string) - GetManagedBy() string - SetManagedBy(string) -} - -func MutateMeta(o Meta, obj interfaces.Object) error { - obj.SetLabels(o.GetLabels()) - if len(obj.GetName()) == 0 { - obj.SetName(o.GetName()) - - } - - if len(obj.GetNamespace()) == 0 { - obj.SetNamespace(o.GetNamespace()) - } - - return nil -} diff --git a/meta/object.go b/meta/object.go index e6763bf..e16612d 100644 --- a/meta/object.go +++ b/meta/object.go @@ -15,15 +15,12 @@ limitations under the License. package meta -import "fmt" - // +kubebuilder:object:generate=true type ObjectMeta struct { Name string `json:"name,omitempty"` Namespace string `json:"namespace,omitempty"` Labels map[string]string `json:"labels,omitempty"` Annotations map[string]string `json:"annotations,omitempty"` - Finalizers map[string]string `json:"finalizers,omitempty"` } func (c *ObjectMeta) SetLabels(labels map[string]string) { @@ -39,12 +36,23 @@ func (c *ObjectMeta) SetLabels(labels map[string]string) { } } +func (c *ObjectMeta) SetAnnotations(annotations map[string]string) { + if len(c.Annotations) == 0 { + c.Annotations = make(map[string]string) + } + if len(annotations) > 0 { + for k, v := range annotations { + if len(c.Annotations[k]) == 0 { + c.Annotations[k] = v + } + } + } +} + func (c *ObjectMeta) GetLabels() map[string]string { return c.Labels } func (c *ObjectMeta) GetAnnotations() map[string]string { return c.Annotations } -func (c *ObjectMeta) GetFinalizers() map[string]string { return c.Finalizers } - func (o *ObjectMeta) GetName() string { return o.Name } func (o *ObjectMeta) SetName(name string) { o.Name = name } @@ -76,19 +84,3 @@ func (c *ObjectMeta) SetPartOf(s string) { c.Labels["app.kubernetes.io/part-of"] func (c *ObjectMeta) GetManagedBy() string { return c.Labels["app.kubernetes.io/managed-by"] } func (c *ObjectMeta) SetManagedBy(s string) { c.Labels["app.kubernetes.io/managed-by"] = s } - -func Init(om *ObjectMeta) { - if om == nil { - om = new(ObjectMeta) - } - if len(om.Labels) == 0 { - om.Labels = make(map[string]string) - } - fmt.Println(om) -} - -func New() *ObjectMeta { - om := new(ObjectMeta) - om.Labels = make(map[string]string) - return om -} diff --git a/meta/zz_generated.deepcopy.go b/meta/zz_generated.deepcopy.go index a592266..7acc2a0 100644 --- a/meta/zz_generated.deepcopy.go +++ b/meta/zz_generated.deepcopy.go @@ -38,13 +38,6 @@ func (in *ObjectMeta) DeepCopyInto(out *ObjectMeta) { (*out)[key] = val } } - if in.Finalizers != nil { - in, out := &in.Finalizers, &out.Finalizers - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectMeta. diff --git a/objects/container/object.go b/objects/container/object.go index 12b392f..a202ac0 100644 --- a/objects/container/object.go +++ b/objects/container/object.go @@ -23,7 +23,7 @@ import ( // +kubebuilder:object:generate=true type Container struct { *TemplateSpec `json:",inline"` - parameters.Settings `json:"parameters,omitempty"` + *parameters.EnvSpec `json:"parameters,omitempty"` } // +kubebuilder:object:generate=true @@ -50,12 +50,3 @@ func (r *TemplateSpec) GetContainerPorts() []corev1.ContainerPort { return func (r *TemplateSpec) GetContainerLivenessProbe() *corev1.Probe { return r.LivenessProbe } func (r *TemplateSpec) GetContainerReadinessProbe() *corev1.Probe { return r.ReadinessProbe } func (r *TemplateSpec) GetContainerArgs() []string { return r.Args } - -// func (r *TemplateSpec) GetParameters() parameters.Parameters { return nil } - -//func NewContainer(spec *TemplateSpec, p parameters.Parameters) *Container { -// return &Container{ -// Parameters: p, -// TemplateSpec: spec, -// } -//} diff --git a/objects/container/zz_generated.deepcopy.go b/objects/container/zz_generated.deepcopy.go index e0fb9d7..7000ead 100644 --- a/objects/container/zz_generated.deepcopy.go +++ b/objects/container/zz_generated.deepcopy.go @@ -31,7 +31,10 @@ func (in *Container) DeepCopyInto(out *Container) { *out = new(TemplateSpec) (*in).DeepCopyInto(*out) } - in.Settings.DeepCopyInto(&out.Settings) + if in.EnvSpec != nil { + in, out := &in.EnvSpec, &out.EnvSpec + *out = (*in).DeepCopy() + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Container. diff --git a/objects/ingress/object.go b/objects/ingress/object.go index d7f7899..bc312b0 100644 --- a/objects/ingress/object.go +++ b/objects/ingress/object.go @@ -3,7 +3,6 @@ package ingress import ( interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" - parameters "k8s.libre.sh/settings" networkingv1beta1 "k8s.io/api/networking/v1beta1" ) @@ -31,5 +30,3 @@ func (o *Ingress) Mutate(obj interfaces.Object) error { func (o *Ingress) GetObject() interfaces.Object { return &networkingv1beta1.Ingress{} } - -func (o *Ingress) SetSettings(parameters parameters.Parameters) {} diff --git a/objects/service/object.go b/objects/service/object.go index 7718a5b..ae77510 100644 --- a/objects/service/object.go +++ b/objects/service/object.go @@ -3,7 +3,6 @@ package service import ( interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" - settings "k8s.libre.sh/settings" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -34,14 +33,6 @@ type Port struct { // Ingress Ingress `json:"ingress,omitempty"` } -// type Ingress struct { -// Path string `json:"ingress,omitempty"` -// Host Host `json:"host,omitempty"` -// TLS bool `json:"tls,omitempty"` -//} - -func (o *Service) SetSettings(parameters settings.Parameters) {} - func (r *ServiceSpec) GetServiceType() corev1.ServiceType { return r.Type } func (r *ServiceSpec) GetServicePorts() []corev1.ServicePort { diff --git a/settings/env.go b/settings/env.go new file mode 100644 index 0000000..f8eed13 --- /dev/null +++ b/settings/env.go @@ -0,0 +1,127 @@ +/* + +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 settings + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.libre.sh/utils" +) + +// +kubebuilder:object:generate=true +type EnvSpec struct { + SecretRefs []string `json:"secretRefs,omitempty"` + ConfigRefs []string `json:"configRefs,omitempty"` + *Parameters `json:"parameters,omitempty"` +} + +func (s *EnvSpec) SetParameters(parameters *Parameters) { s.Parameters = parameters } + +func (s *EnvSpec) GetParameters() *Parameters { + if s.Parameters == nil { + s.Parameters = new(Parameters) + } + return s.Parameters +} +func (s *EnvSpec) GetConfigRefs() []string { return s.ConfigRefs } + +func (s *EnvSpec) SetConfigRefs(refs []string) { s.ConfigRefs = refs } + +func (s *EnvSpec) GetSecretRefs() []string { return s.SecretRefs } + +func (s *EnvSpec) SetSecretRefs(refs []string) { s.SecretRefs = refs } + +func (e *EnvSpec) GetEnvFrom() []corev1.EnvFromSource { + envFroms := []corev1.EnvFromSource{} + envFrom := corev1.EnvFromSource{} + + for _, p := range *e.Parameters { + if len(p.Ref) > 0 { + if p.MountType == MountEnvFile { + if p.Type == ConfigParameter { + e.ConfigRefs = append(e.ConfigRefs, p.Ref) + } else if p.Type != ObjectFieldParameter { + e.SecretRefs = append(e.SecretRefs, p.Ref) + } + } + } + } + + e.SecretRefs = utils.Unique(e.SecretRefs) + e.ConfigRefs = utils.Unique(e.ConfigRefs) + + if len(e.ConfigRefs) > 0 { + for _, configRef := range e.ConfigRefs { + envFrom = corev1.EnvFromSource{ + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: configRef, + }, + }, + } + envFroms = append(envFroms, envFrom) + } + } + + if len(e.SecretRefs) > 0 { + for _, secretRef := range e.SecretRefs { + envFrom = corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: secretRef, + }, + }, + } + envFroms = append(envFroms, envFrom) + } + } + + if len(envFroms) > 0 { + return envFroms + } + + return nil +} + +// We need to manually change this autogenerated function as it is broken with Paramete drs type, its trying to do new([]*Parameter) instead of new(Parameters) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EnvSpec) DeepCopyInto(out *EnvSpec) { + *out = *in + if in.SecretRefs != nil { + in, out := &in.SecretRefs, &out.SecretRefs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.ConfigRefs != nil { + in, out := &in.ConfigRefs, &out.ConfigRefs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + *out = new(Parameters) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. +func (in *EnvSpec) DeepCopy() *EnvSpec { + if in == nil { + return nil + } + out := new(EnvSpec) + in.DeepCopyInto(out) + return out +} diff --git a/settings/interface.go b/settings/interface.go index 3d872ef..9952e40 100644 --- a/settings/interface.go +++ b/settings/interface.go @@ -15,53 +15,36 @@ limitations under the License. package settings -type Interface interface { - // GetConfigParameters() *Parameters - // SetConfigParameters(*Parameters) +type Env interface { GetConfigRefs() []string SetConfigRefs([]string) - GetParameters() *Parameters SetParameters(*Parameters) - - // GetSecretParameters() *Parameters - // SetSecretParameters(*Parameters) GetSecretRefs() []string SetSecretRefs([]string) + InitRandValues() + InitTemplateValues(map[string]string) error } -func MergeSettings(dependencies, settings Interface) Interface { +func MergeSettings(src, dest Env) Env { - if settings == nil { - settings = dependencies + if dest == nil { + dest = src } else { - settings.SetConfigRefs(append(settings.GetConfigRefs(), dependencies.GetConfigRefs()...)) - settings.SetSecretRefs(append(settings.GetSecretRefs(), dependencies.GetSecretRefs()...)) + dest.SetConfigRefs(append(dest.GetConfigRefs(), src.GetConfigRefs()...)) + dest.SetSecretRefs(append(dest.GetSecretRefs(), src.GetSecretRefs()...)) - params := *settings.GetParameters() + params := *dest.GetParameters() if params == nil { - params = *dependencies.GetParameters() + params = *src.GetParameters() } else { - for _, p := range *dependencies.GetParameters() { + for _, p := range *src.GetParameters() { params = append(params, p) } } - settings.SetParameters(¶ms) + dest.SetParameters(¶ms) } - return settings + return dest } - -/* type Env interface { - GetName() string // GetKey() - SetName(string) // GetKey() - GetValue() string - SetValue(string) - GetLocalObjectRef() string - SetLocalObjectRef(string) - GetFromKey() string // GetKey() if GetName() ?? - SetFromKey(string) // GetKey() if GetName() ?? - GetType() ParameterType - // GetMountType() MountType -} */ diff --git a/settings/parameter.go b/settings/parameter.go index f196901..9a00e8a 100644 --- a/settings/parameter.go +++ b/settings/parameter.go @@ -26,9 +26,7 @@ const ( MountLiteral MountType = "literal" MountFrom MountType = "from" MountFile MountType = "file" - -// MountEnvVar MountType = "envVar" -// MountEnvVarFrom MountType = "envVarFrom" + MountEnvFile MountType = "envFile" ) const ( @@ -66,21 +64,11 @@ type ValueFrom struct { FromKey string `json:"fromKey,omitempty"` // Ref is a reference to a local object, set ParameterType to define the object Ref string `json:"ref,omitempty"` + // Type specifies if its a ConfigMap or Secret + SourceType ParameterType `json:"type,omitempty"` } type MountPath struct { Path string `json:"path,omitempty"` SubPath string `json:"subPath,omitempty"` } - -// +kubebuilder:object:generate=true -type SecretParam struct { - // Key that will be mounted as environment variable - Key string `json:"key,omitempty"` - // ValueFrom specifies where to get the value from for the parameter - ValueFrom `json:",inline"` - // Source of the Secret or ConfigMap - Destination string `json:"destination,omitempty"` - // Source of the Secret or ConfigMap - Generate bool `json:"generate,omitempty"` -} diff --git a/settings/parameter_helper.go b/settings/parameter_helper.go index 9406d6f..f84e02e 100644 --- a/settings/parameter_helper.go +++ b/settings/parameter_helper.go @@ -24,6 +24,7 @@ import ( func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { switch p.MountType { + case MountLiteral: if len(p.Value) > 0 && len(p.Key) > 0 { envVar := corev1.EnvVar{ @@ -50,6 +51,7 @@ func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { }, } return envVar, nil + case ConfigParameter: envVar = corev1.EnvVar{ Name: p.Key, @@ -63,6 +65,7 @@ func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { }, } return envVar, nil + case ObjectFieldParameter: envVar = corev1.EnvVar{ Name: p.Key, @@ -77,6 +80,7 @@ func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { } } return envVar, errors.New("missing arguments") + default: return envVar, errors.New("wrong MountType") } diff --git a/settings/parameters_helpers.go b/settings/parameters_helpers.go index c5c6dfe..15366fd 100644 --- a/settings/parameters_helpers.go +++ b/settings/parameters_helpers.go @@ -17,7 +17,6 @@ package settings import ( "bytes" - "reflect" "text/template" "github.com/presslabs/controller-util/rand" @@ -26,7 +25,7 @@ import ( func (p *Parameters) InitValues() { p.InitRandValues() - p.InitTemplateValues(p.KeyPairValues()) + p.InitTemplateValues(KeyPairValues(p)) } func (p *Parameters) InitRandValues() { @@ -53,91 +52,35 @@ func (p *Parameters) InitRandValues() { } } -func (p *Parameters) InitTemplateValues(values map[string]string) { +func (p *Parameters) InitTemplateValues(values map[string]string) error { for _, param := range *p { if param.Generate == GenerateTemplate { tmpl, err := template.New(param.Key).Parse(param.Value) if err != nil { - // return nil, err + return err } var tpl bytes.Buffer err = tmpl.Execute(&tpl, values) if err != nil { - // return nil, err + return err } param.Value = tpl.String() } } -} - -func (p *Parameters) SortByMountType() map[MountType]Parameters { - data := make(map[MountType]Parameters) - - for _, param := range *p { - data[param.MountType] = append(data[param.MountType], param) - } - - return data -} - -func (p *Parameters) KeyPairValues() map[string]string { - data := make(map[string]string) - - sorted := p.SortByMountType() - - for _, param := range sorted[MountLiteral] { - - if len(param.Value) > 0 && len(param.Key) > 0 { - data[param.Key] = param.Value - } - - } - - for _, param := range sorted[MountFrom] { - - if len(param.Value) > 0 && len(param.Key) > 0 { - data[param.Key] = param.Value - } - } - - return data + return nil } func (p *Parameters) GetData() map[string]string { data := make(map[string]string) for _, param := range *p { - if param.MountType == MountFrom && param.Type != ObjectFieldParameter && len(param.Value) > 0 { - data[param.Key] = param.Value - } - } - - return data -} - -func (p *Parameters) GetSecretData() map[string]string { - data := make(map[string]string) - - for _, param := range *p { - if param.MountType == MountFrom && param.Type == SecretParameter { - data[param.Key] = param.Value - } - } - - return data -} - -func (p *Parameters) GetConfigData() map[string]string { - data := make(map[string]string) - - for _, param := range *p { - if param.MountType == MountFrom && - param.Type == ConfigParameter && + if param.MountType == MountEnvFile && + param.Type != ObjectFieldParameter && len(param.Value) > 0 { data[param.Key] = param.Value } @@ -163,41 +106,8 @@ func (p *Parameters) GetEnv() []corev1.EnvVar { } } - // TODO IMPROVE if len(envVars) > 0 { return envVars } return nil } - -func Marshal(i interface{}) (Parameters, error) { - parameters := Parameters{} - - t := reflect.TypeOf(i) - - ifv := reflect.ValueOf(i) - - for ii := 0; ii < t.NumField(); ii++ { - f := t.Field(ii) - - fv := ifv.Field(ii) - - parameter, ok := fv.Interface().(Parameter) - if !ok { - // return nil, ok - } - - env, ok := f.Tag.Lookup("env") - if !ok { - // return nil, ok - } - - if len(parameter.Key) == 0 { - parameter.Key = env - } - - parameters = append(parameters, ¶meter) - } - - return parameters, nil -} diff --git a/settings/settings.go b/settings/settings.go index e4eda53..84f8d29 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -16,196 +16,26 @@ limitations under the License. package settings import ( - corev1 "k8s.io/api/core/v1" + "k8s.libre.sh/meta" ) -type Settings struct { - *EnvFrom `json:",inline"` - *Parameters `json:"parameters,omitempty"` -} - // +kubebuilder:object:generate=true -type EnvFrom struct { - SecretRefs []string `json:"secretRefs,omitempty"` - ConfigRefs []string `json:"configRefs,omitempty"` -} - -func (s *Settings) SetParameters(parameters *Parameters) { - s.Parameters = parameters -} - -func (s *Settings) GetParameters() *Parameters { - if s.Parameters == nil { - s.Parameters = new(Parameters) - } - return s.Parameters -} - -func (s *Settings) GetSecretRefs() []string { - if s.EnvFrom != nil { - return s.EnvFrom.SecretRefs - } - - return nil -} - -func (s *Settings) SetSecretRefs(refs []string) { - if s.EnvFrom == nil { - s.EnvFrom = new(EnvFrom) - } - s.SecretRefs = refs -} - -func (s *Settings) GetConfigRefs() []string { - if s.EnvFrom != nil { - return s.EnvFrom.ConfigRefs - } - - return nil -} - -func (s *Settings) SetConfigRefs(refs []string) { - if s.EnvFrom == nil { - s.EnvFrom = new(EnvFrom) - } - s.ConfigRefs = refs -} - -/* -type SecretParameters struct { - Refs []string `json:"configRefs,omitempty"` - *Parameters `json:"parameters,omitempty"` -} - -func (s *Settings) GetEnvFrom() []corev1.EnvFromSource { - envFrom := []corev1.EnvFromSource{} - if len(s.Secrets.GetEnvFrom()) > 0 { - envFrom = append(envFrom, s.Secrets.GetEnvFrom()...) - } - if len(s.Parameters.GetEnvFrom()) > 0 { - envFrom = append(envFrom, s.Parameters.GetEnvFrom()...) - } - return envFrom -} - -func (e *SecretParameters) GetEnvFrom() []corev1.EnvFromSource { - envFroms := []corev1.EnvFromSource{} - envFrom := corev1.EnvFromSource{} - - if e != nil { - // if len(e.Refs) > 0 { - for _, ref := range e.Refs { - envFrom = corev1.EnvFromSource{ - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: ref, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - // } - } - - if len(envFroms) > 0 { - return envFroms - } - - return nil -} - -type ConfigParameters struct { - Refs []string `json:"configRefs,omitempty"` - *Parameters `json:"parameters,omitempty"` -} - -func (e *ConfigParameters) GetEnvFrom() []corev1.EnvFromSource { - envFroms := []corev1.EnvFromSource{} - envFrom := corev1.EnvFromSource{} - - if e != nil { - // if len(e.Refs) > 0 { - for _, ref := range e.Refs { - envFrom = corev1.EnvFromSource{ - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: ref, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - // } - } - - if len(envFroms) > 0 { - return envFroms - } - - return nil +type Settings struct { + CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` + SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` + ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + *EnvSpec `json:",inline"` } -*/ -func (e *EnvFrom) GetEnvFrom() []corev1.EnvFromSource { - envFroms := []corev1.EnvFromSource{} - envFrom := corev1.EnvFromSource{} - - if e != nil { - if len(e.ConfigRefs) > 0 { - for _, configRef := range e.ConfigRefs { - envFrom = corev1.EnvFromSource{ - ConfigMapRef: &corev1.ConfigMapEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: configRef, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - } - if len(e.SecretRefs) > 0 { - for _, secretRef := range e.SecretRefs { - envFrom = corev1.EnvFromSource{ - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: secretRef, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - } - } +func (s *Settings) GetEnv() Env { return s.EnvSpec } - if len(envFroms) > 0 { - return envFroms - } +func (s *Settings) GetMeta() meta.Instance { return s.CommonMeta } - return nil -} +func (s *Settings) GetSecretMeta() meta.Instance { return s.SecretMeta } -// We need to manually change this autogenerated function as it is broken with Paramete drs type, its trying to do new([]*Parameter) instead of new(Parameters) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Settings) DeepCopyInto(out *Settings) { - *out = *in - if in.EnvFrom != nil { - in, out := &in.EnvFrom, &out.EnvFrom - *out = new(EnvFrom) - (*in).DeepCopyInto(*out) - } - if in.Parameters != nil { - in, out := &in.Parameters, &out.Parameters - *out = new(Parameters) - (*in).DeepCopyInto(*out) - } -} +func (s *Settings) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. -func (in *Settings) DeepCopy() *Settings { - if in == nil { - return nil - } - out := new(Settings) - in.DeepCopyInto(out) - return out +func (s *Settings) SetDefaults() { + meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) + meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) } diff --git a/settings/utils.go b/settings/utils.go new file mode 100644 index 0000000..36885cd --- /dev/null +++ b/settings/utils.go @@ -0,0 +1,101 @@ +/* + +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 settings + +import ( + "reflect" +) + +func Marshal(i interface{}) (Parameters, error) { + parameters := Parameters{} + + t := reflect.TypeOf(i) + + ifv := reflect.ValueOf(i) + + for ii := 0; ii < t.NumField(); ii++ { + f := t.Field(ii) + + fv := ifv.Field(ii) + + parameter, ok := fv.Interface().(Parameter) + if !ok { + // return nil, ok + } + + env, ok := f.Tag.Lookup("env") + if !ok { + // return nil, ok + } + + if len(parameter.Key) == 0 { + parameter.Key = env + } + + if len(parameter.MountType) == 0 { + parameter.MountType = MountEnvFile + } + + parameters = append(parameters, ¶meter) + } + + return parameters, nil +} + +func ParametersByKey(p *Parameters) map[string]*Parameter { + paramsByKey := map[string]*Parameter{} + + for _, p := range *p { + paramsByKey[p.Key] = p + } + + return paramsByKey +} + +func OrderByResourceRef(s *EnvSpec) (secrets, configs map[string]Parameters) { + secrets = make(map[string]Parameters) + configs = make(map[string]Parameters) + + // We order the parameters by secret and configmap sources + // First we get the sources provided as resources that should be mounted untouched + for _, ref := range s.SecretRefs { + secrets[ref] = Parameters{} + } + for _, ref := range s.ConfigRefs { + configs[ref] = Parameters{} + } + + // Then we get the sources that are provided for each parameters and will need a transformation + for _, p := range *s.Parameters { + if len(p.ValueFrom.Ref) > 0 && p.Type == SecretParameter { + secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p) + } + if len(p.ValueFrom.Ref) > 0 && p.Type == ConfigParameter { + configs[p.ValueFrom.Ref] = append(configs[p.ValueFrom.Ref], p) + } + } + return secrets, configs +} + +func KeyPairValues(p *Parameters) map[string]string { + data := make(map[string]string) + + for _, param := range *p { + data[param.Key] = param.Value + } + + return data +} diff --git a/settings/zz_generated.deepcopy.go b/settings/zz_generated.deepcopy.go index be6342e..1a04750 100644 --- a/settings/zz_generated.deepcopy.go +++ b/settings/zz_generated.deepcopy.go @@ -21,31 +21,6 @@ package settings import () -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EnvFrom) DeepCopyInto(out *EnvFrom) { - *out = *in - if in.SecretRefs != nil { - in, out := &in.SecretRefs, &out.SecretRefs - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ConfigRefs != nil { - in, out := &in.ConfigRefs, &out.ConfigRefs - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EnvFrom. -func (in *EnvFrom) DeepCopy() *EnvFrom { - if in == nil { - return nil - } - out := new(EnvFrom) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Parameter) DeepCopyInto(out *Parameter) { *out = *in @@ -87,19 +62,3 @@ func (in Parameters) DeepCopy() Parameters { in.DeepCopyInto(out) return *out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecretParam) DeepCopyInto(out *SecretParam) { - *out = *in - out.ValueFrom = in.ValueFrom -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretParam. -func (in *SecretParam) DeepCopy() *SecretParam { - if in == nil { - return nil - } - out := new(SecretParam) - in.DeepCopyInto(out) - return out -} diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..ce6433a --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,13 @@ +package utils + +func Unique(stringSlice []string) []string { + keys := make(map[string]bool) + list := []string{} + for _, entry := range stringSlice { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +} -- GitLab From 445a2c2d6ca52ff87b356a45fbd75a535f9783b5 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 18 May 2020 23:20:32 +0200 Subject: [PATCH 02/18] reorganize --- {instance => application}/component.go | 11 +- .../components}/network.go | 25 ++- application/components/settings.go | 170 ++++++++++++++ .../components}/workload.go | 41 ++-- .../components}/zz_generated.deepcopy.go | 4 +- application/instance.go | 100 +++++++++ {instance => application}/settings.go | 36 ++- .../env.go => application/settings/config.go | 61 ++--- .../settings}/interface.go | 10 +- .../settings/parameters}/parameter.go | 2 +- .../settings/parameters}/parameter_helper.go | 2 +- .../parameters}/parameters_helpers.go | 49 +++- .../parameters}/parameters_suite_test.go | 2 +- .../settings/parameters}/parameters_test.go | 169 +++++++------- .../settings/parameters}/utils.go | 28 +-- .../parameters}/zz_generated.deepcopy.go | 2 +- application/settings/utils.go | 43 ++++ cover.out | 88 ++++++++ instance/instance.go | 211 ------------------ objects/configmap/object.go | 2 +- objects/configmap/zz_generated.deepcopy.go | 6 +- objects/container/mutate.go | 5 +- objects/container/object.go | 6 +- objects/container/zz_generated.deepcopy.go | 4 +- {instance => objects}/object.go | 2 +- objects/pod/pod_suite_test.go | 13 -- objects/pod/pod_test.go | 75 ------- objects/secret/object.go | 2 +- objects/secret/zz_generated.deepcopy.go | 6 +- objects/service/mutate.go | 2 +- settings/settings.go | 41 ---- 31 files changed, 663 insertions(+), 555 deletions(-) rename {instance => application}/component.go (74%) rename {components => application/components}/network.go (85%) create mode 100644 application/components/settings.go rename {components => application/components}/workload.go (66%) rename {components => application/components}/zz_generated.deepcopy.go (97%) create mode 100644 application/instance.go rename {instance => application}/settings.go (65%) rename settings/env.go => application/settings/config.go (57%) rename {settings => application/settings}/interface.go (84%) rename {settings => application/settings/parameters}/parameter.go (99%) rename {settings => application/settings/parameters}/parameter_helper.go (99%) rename {settings => application/settings/parameters}/parameters_helpers.go (65%) rename {settings => application/settings/parameters}/parameters_suite_test.go (88%) rename {settings => application/settings/parameters}/parameters_test.go (69%) rename {settings => application/settings/parameters}/utils.go (62%) rename {settings => application/settings/parameters}/zz_generated.deepcopy.go (98%) create mode 100644 application/settings/utils.go create mode 100644 cover.out delete mode 100644 instance/instance.go rename {instance => objects}/object.go (98%) delete mode 100644 objects/pod/pod_suite_test.go delete mode 100644 objects/pod/pod_test.go delete mode 100644 settings/settings.go diff --git a/instance/component.go b/application/component.go similarity index 74% rename from instance/component.go rename to application/component.go index fabf2cb..e95669d 100644 --- a/instance/component.go +++ b/application/component.go @@ -1,10 +1,11 @@ -package instance +package application import ( "github.com/presslabs/controller-util/syncer" + settings "k8s.libre.sh/application/settings" interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" - parameters "k8s.libre.sh/settings" + objects "k8s.libre.sh/objects" ) type Component interface { @@ -12,9 +13,9 @@ type Component interface { GetMeta() meta.Instance SetDefaults() Init() - GetObjects() map[int]Object + GetObjects() map[int]objects.Object HasDependencies() bool - GetDependencies() parameters.Env + GetDependencies() settings.Config // SetDependencies(*parameters.Settings) } @@ -22,7 +23,7 @@ func NewSyncer(i Component, r interfaces.Reconcile, owner interfaces.Object) (sy mutators := i.GetObjects() for _, m := range mutators { - syncers = append(syncers, NewObjectSyncer(m, owner, r)) + syncers = append(syncers, objects.NewObjectSyncer(m, owner, r)) } return syncers diff --git a/components/network.go b/application/components/network.go similarity index 85% rename from components/network.go rename to application/components/network.go index 669cd5f..601a7e0 100644 --- a/components/network.go +++ b/application/components/network.go @@ -29,22 +29,28 @@ import ( service "k8s.libre.sh/objects/service" ) -type Serv struct { - *meta.ObjectMeta `json:"commonMeta,omitempty"` +type Network struct { + IngressMeta *meta.ObjectMeta `json:"ingressMeta,omitempty"` + ServiceMeta *meta.ObjectMeta `json:"serviceMeta,omitempty"` + *Backend `json:"backend,inline"` +} + +type Service struct { + *meta.ObjectMeta `json:"meta,omitempty"` *Backend `json:"backend,omitempty"` } -func (s *Serv) Mutate(obj interfaces.Object) error { +func (s *Service) Mutate(obj interfaces.Object) error { service.MutateService(s, obj.(*corev1.Service), s.ObjectMeta) meta.MutateMeta(s, obj) return nil } -func (s *Serv) GetObject() interfaces.Object { +func (s *Service) GetObject() interfaces.Object { return &corev1.Service{} } -type Ing struct { +type Ingress struct { *meta.ObjectMeta `json:"commonMeta,omitempty"` Backends []Backend `json:"backends,omitempty"` } @@ -60,14 +66,13 @@ type Backend struct { ServiceType corev1.ServiceType `json:"type,omitempty"` } -func (i *Ing) Mutate(obj interfaces.Object) error { - // o.Service.Meta = o.Meta +func (i *Ingress) Mutate(obj interfaces.Object) error { ingress.MutateIngress(i, obj.(*networkingv1beta1.Ingress)) meta.MutateMeta(i, obj) return nil } -func (i *Ing) GetObject() interfaces.Object { +func (i *Ingress) GetObject() interfaces.Object { return &networkingv1beta1.Ingress{} } @@ -129,7 +134,7 @@ func (b *Backend) GetIngressRule() networkingv1beta1.IngressRule { return rule } -func (i *Ing) GetIngressRules() []networkingv1beta1.IngressRule { +func (i *Ingress) GetIngressRules() []networkingv1beta1.IngressRule { rules := []networkingv1beta1.IngressRule{} @@ -156,7 +161,7 @@ func (b *Backend) GetIngressTLS() networkingv1beta1.IngressTLS { return tls } -func (i *Ing) GetIngressTLS() []networkingv1beta1.IngressTLS { +func (i *Ingress) GetIngressTLS() []networkingv1beta1.IngressTLS { tlsList := []networkingv1beta1.IngressTLS{} diff --git a/application/components/settings.go b/application/components/settings.go new file mode 100644 index 0000000..ab1d060 --- /dev/null +++ b/application/components/settings.go @@ -0,0 +1,170 @@ +/* + +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 components + +import ( + corev1 "k8s.io/api/core/v1" + "sigs.k8s.io/controller-runtime/pkg/client" + + "k8s.libre.sh/application/settings" + "k8s.libre.sh/application/settings/parameters" + "k8s.libre.sh/meta" + "k8s.libre.sh/objects" + "k8s.libre.sh/objects/configmap" + "k8s.libre.sh/objects/secret" +) + +// +kubebuilder:object:generate=true +type Settings struct { + CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` + SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` + ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + *settings.ConfigSpec `json:",inline"` +} + +func (s *Settings) GetConfig() settings.Config { return s.ConfigSpec } + +func (s *Settings) GetMeta() meta.Instance { return s.CommonMeta } + +func (s *Settings) GetSecretMeta() meta.Instance { return s.SecretMeta } + +func (s *Settings) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } + +func (s *Settings) SetDefaults() { + meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) + meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) +} + +func (s *Settings) GetObjects() map[int]objects.Object { + + cm := &configmap.ConfigMap{ + ObjectMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), + } + + secret := &secret.Secret{ + ObjectMeta: s.GetSecretMeta().(*meta.ObjectMeta), + } + + objs := make(map[int]objects.Object, 2) + + meta.SetObjectMeta(s.CommonMeta, cm.ObjectMeta) + meta.SetObjectMeta(s.CommonMeta, secret.ObjectMeta) + + // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS + params := s.GetConfig() + + for _, p := range *params.GetParameters() { + // TODO check not mountLiteral ?? + if p.MountType == parameters.MountEnvFile && + p.Type == parameters.SecretParameter && + len(p.Value) > 0 { + secret.Parameters = append(secret.Parameters, p) + } + if p.MountType == parameters.MountEnvFile && + p.Type == parameters.ConfigParameter && + len(p.Value) > 0 { + cm.Parameters = append(cm.Parameters, p) + } + } + + // TODO IMPROVEparameeters + if len(cm.Parameters) > 0 { + objs[0] = cm + } + + if len(secret.Parameters) > 0 { + // secret.Parameters = secretParameters + if objs[0] == nil { + objs[0] = secret + + } else { + objs[1] = secret + } + } + + return objs +} + +func (s *Settings) Init(c client.Client) error { + + // TODO ADD SECRET REFS HERE ?? + + err := InitParametersValueFrom(s, c) + + if err != nil { + return err + } + + s.InitRandValues() + + err = s.InitTemplateValues(parameters.KeyPairValues(s.Parameters)) + + return nil +} + +// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace +// All parameters values are filled from those resources +func InitParametersValueFrom(s *Settings, c client.Client) error { + // params := s.GetParameters().(*parameters.Settings) + + params := parameters.Parameters{} + + paramsByKey := parameters.ParametersByKey(s.Parameters) + paramsBySecretSource, paramsByConfigMapSource := settings.OrderByResourceRef(s.ConfigSpec) + + cm := &corev1.ConfigMap{} + sec := &corev1.Secret{} + + cm.SetNamespace(s.CommonMeta.GetNamespace()) + sec.SetNamespace(s.CommonMeta.GetNamespace()) + + // We get the secrets + for k, v := range paramsBySecretSource { + sec.SetName(k) + + err := parameters.GetAndMergeParameters(v, paramsByKey, c, sec) + if err != nil { + return err + } + } + + for k, v := range paramsByConfigMapSource { + cm.SetName(k) + err := parameters.GetAndMergeParameters(v, paramsByKey, c, sec) + if err != nil { + return err + } + } + + for _, v := range paramsByKey { + if v.MountType == parameters.MountEnvFile { + if v.Type == parameters.ConfigParameter { + v.Ref = s.GetConfigMapMeta().GetName() + } + if v.Type == parameters.SecretParameter { + v.Ref = s.GetSecretMeta().GetName() + } + } + params = append(params, v) + } + + // TODO FIX THIS we need to check if we want to mount as EnvFile and reset old resources references + s.SecretRefs = []string{} + s.ConfigRefs = []string{} + s.Parameters = ¶ms + + return nil +} diff --git a/components/workload.go b/application/components/workload.go similarity index 66% rename from components/workload.go rename to application/components/workload.go index 4f372e6..d981964 100644 --- a/components/workload.go +++ b/application/components/workload.go @@ -16,17 +16,17 @@ limitations under the License. package components import ( - instance "k8s.libre.sh/instance" + settings "k8s.libre.sh/application/settings" meta "k8s.libre.sh/meta" + "k8s.libre.sh/objects" deployment "k8s.libre.sh/objects/deployment" - parameters "k8s.libre.sh/settings" ) // +kubebuilder:object:generate=true type Workload struct { *meta.ObjectMeta `json:"commonMeta,omitempty"` *deployment.Deployment `json:"deployment,omitempty"` - *Backend `json:"network,omitempty"` + *Network `json:"network,omitempty"` Dependencies bool `json:"dependencies,omitempty"` } @@ -38,21 +38,27 @@ func (w *Workload) GetMeta() meta.Instance { return w.ObjectMeta } -func (w *Workload) GetObjects() map[int]instance.Object { +func (w *Workload) GetObjects() map[int]objects.Object { - objects := make(map[int]instance.Object) + objects := make(map[int]objects.Object) - ing := &Ing{ - ObjectMeta: &meta.ObjectMeta{}, + ing := &Ingress{ + // TODO TO FIX + ObjectMeta: w.IngressMeta, Backends: []Backend{ *w.Backend, }, } - srv := &Serv{ - ObjectMeta: &meta.ObjectMeta{}, + + srv := &Service{ + // TODO TO FIX + ObjectMeta: w.ServiceMeta, Backend: w.Backend, } + meta.SetObjectMeta(w.ObjectMeta, ing.ObjectMeta) + meta.SetObjectMeta(w.ObjectMeta, srv.ObjectMeta) + objects[0] = srv objects[1] = ing objects[2] = w.Deployment @@ -60,15 +66,15 @@ func (w *Workload) GetObjects() map[int]instance.Object { return objects } -func (w *Workload) SetDependencies(s *parameters.Settings) { w.EnvSpec = s.EnvSpec } -func (w *Workload) GetDependencies() parameters.Env { return w.EnvSpec } +func (w *Workload) SetDependencies(s *Settings) { w.ConfigSpec = s.ConfigSpec } +func (w *Workload) GetDependencies() settings.Config { return w.ConfigSpec } func (w *Workload) SetDefaults() { // TODO FIXME w.Dependencies = true - w.Backend.ServiceName = w.GetName() + w.Backend.ServiceName = w.ServiceMeta.GetName() } func (w *Workload) Init() { @@ -89,12 +95,19 @@ func (w *Workload) Init() { w.Deployment.ObjectMeta = new(meta.ObjectMeta) } - if w.EnvSpec == nil { - w.EnvSpec = new(parameters.EnvSpec) + if w.ConfigSpec == nil { + w.ConfigSpec = new(settings.ConfigSpec) } if w.Backend == nil { w.Backend = &Backend{} } + if w.ServiceMeta == nil { + w.ServiceMeta = new(meta.ObjectMeta) + } + + if w.IngressMeta == nil { + w.IngressMeta = new(meta.ObjectMeta) + } } diff --git a/components/zz_generated.deepcopy.go b/application/components/zz_generated.deepcopy.go similarity index 97% rename from components/zz_generated.deepcopy.go rename to application/components/zz_generated.deepcopy.go index 6b5487f..30bad83 100644 --- a/components/zz_generated.deepcopy.go +++ b/application/components/zz_generated.deepcopy.go @@ -63,8 +63,8 @@ func (in *Settings) DeepCopyInto(out *Settings) { *out = new(meta.ObjectMeta) (*in).DeepCopyInto(*out) } - if in.EnvSpec != nil { - in, out := &in.EnvSpec, &out.EnvSpec + if in.ConfigSpec != nil { + in, out := &in.ConfigSpec, &out.ConfigSpec *out = (*in).DeepCopy() } } diff --git a/application/instance.go b/application/instance.go new file mode 100644 index 0000000..05238ae --- /dev/null +++ b/application/instance.go @@ -0,0 +1,100 @@ +package application + +import ( + "context" + + "github.com/presslabs/controller-util/syncer" + + "k8s.libre.sh/application/components" + settings "k8s.libre.sh/application/settings" + "k8s.libre.sh/interfaces" + "k8s.libre.sh/meta" + "k8s.libre.sh/objects" +) + +type Instance interface { + meta.Instance + GetComponents() map[int]Component + GetOwner() interfaces.Object + GetSettings() Settings + SetDefaults() +} + +func Init(i Instance) { + + i.SetDefaults() + + for _, c := range i.GetComponents() { + c.Init() + + // TODO TOFIX + component := c.GetComponent() + + meta.SetObjectMeta(i, c) + + if len(component) > 0 { + c.SetComponent(component) + } + + for _, o := range c.GetObjects() { + meta.SetObjectMeta(c, o) + // fmt.Println(o.GetName()) + } + + c.SetDefaults() + + } +} + +func NewSyncers(app Instance, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface, err error) { + + //////////////////// + //// Settings ////// + /////////////////// + + // TODO TO FIX SHOULD BE RUN IN INITIALIZED FUNCTION + // INITIALISE VALUES FROM EXTERNAL RESOURCES, RANDOM & TEMPLATES + // sett := app.GetSettings().GetConfig().(*components.Settings) + sett := app.GetSettings().(*components.Settings) + + err = sett.Init(r.GetClient()) + + if err != nil { + return syncers, err + } + + // Object Syncers + + for _, obj := range sett.GetObjects() { + // meta.SetObjectMeta(sett.CommonMeta, obj) + s := objects.NewObjectSyncer(obj, owner, r) + + if err := syncer.Sync(context.TODO(), s, r.GetRecorder()); err != nil { + // return nil, err + } + + } + + ///////////////////// + //// Components //// + /////////////////// + components := app.GetComponents() + + // TODO TO FIX SHOULD BE RUN IN INITIALIZED FUNCTION + // INITIALIZE + for _, c := range components { + if c.HasDependencies() { + + deps := c.GetDependencies() + deps = settings.MergeSettings(sett, deps) + + } + // GET SYNCERS + mutators := c.GetObjects() + for _, m := range mutators { + syncers = append(syncers, objects.NewObjectSyncer(m, owner, r)) + } + } + return syncers, nil + +} diff --git a/instance/settings.go b/application/settings.go similarity index 65% rename from instance/settings.go rename to application/settings.go index 84b4068..2dfc36c 100644 --- a/instance/settings.go +++ b/application/settings.go @@ -13,24 +13,43 @@ See the License for the specific language governing permissions and limitations under the License. */ -package instance +package application import ( - meta "k8s.libre.sh/meta" + "k8s.libre.sh/application/components" + "k8s.libre.sh/application/settings" + "k8s.libre.sh/application/settings/parameters" + "k8s.libre.sh/meta" + "k8s.libre.sh/objects" "k8s.libre.sh/objects/configmap" - secret "k8s.libre.sh/objects/secret" - parameters "k8s.libre.sh/settings" + "k8s.libre.sh/objects/secret" + + "sigs.k8s.io/controller-runtime/pkg/client" ) type Settings interface { GetMeta() meta.Instance GetSecretMeta() meta.Instance GetConfigMapMeta() meta.Instance - GetEnv() parameters.Env + GetConfig() settings.Config SetDefaults() + Init(c client.Client) error +} + +func NewSettings(s Settings) *components.Settings { + return &components.Settings{ + CommonMeta: s.GetMeta().(*meta.ObjectMeta), + SecretMeta: s.GetSecretMeta().(*meta.ObjectMeta), + ConfigMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), + ConfigSpec: &settings.ConfigSpec{ + ConfigRefs: s.GetConfig().GetConfigRefs(), + SecretRefs: s.GetConfig().GetSecretRefs(), + Parameters: s.GetConfig().GetParameters(), + }, + } } -func GetObjects(s Settings) map[int]Object { +func GetObjects(s Settings) map[int]objects.Object { cm := &configmap.ConfigMap{ ObjectMeta: &meta.ObjectMeta{}, @@ -40,13 +59,13 @@ func GetObjects(s Settings) map[int]Object { ObjectMeta: &meta.ObjectMeta{}, } - objs := make(map[int]Object, 2) + objs := make(map[int]objects.Object, 2) meta.SetObjectMeta(s.GetConfigMapMeta(), cm.ObjectMeta) meta.SetObjectMeta(s.GetSecretMeta(), secret.ObjectMeta) // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS - params := s.GetEnv() + params := s.GetConfig() for _, p := range *params.GetParameters() { // TODO check not mountLiteral ?? @@ -68,7 +87,6 @@ func GetObjects(s Settings) map[int]Object { } if len(secret.Parameters) > 0 { - // secret.Parameters = secretParameters if objs[0] == nil { objs[0] = secret diff --git a/settings/env.go b/application/settings/config.go similarity index 57% rename from settings/env.go rename to application/settings/config.go index f8eed13..72b9d81 100644 --- a/settings/env.go +++ b/application/settings/config.go @@ -17,53 +17,54 @@ package settings import ( corev1 "k8s.io/api/core/v1" + "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/utils" ) // +kubebuilder:object:generate=true -type EnvSpec struct { - SecretRefs []string `json:"secretRefs,omitempty"` - ConfigRefs []string `json:"configRefs,omitempty"` - *Parameters `json:"parameters,omitempty"` +type ConfigSpec struct { + SecretRefs []string `json:"secretRefs,omitempty"` + ConfigRefs []string `json:"configRefs,omitempty"` + *parameters.Parameters `json:"parameters,omitempty"` } -func (s *EnvSpec) SetParameters(parameters *Parameters) { s.Parameters = parameters } +func (c *ConfigSpec) SetParameters(parameters *parameters.Parameters) { c.Parameters = parameters } -func (s *EnvSpec) GetParameters() *Parameters { - if s.Parameters == nil { - s.Parameters = new(Parameters) +func (c *ConfigSpec) GetParameters() *parameters.Parameters { + if c.Parameters == nil { + c.Parameters = new(parameters.Parameters) } - return s.Parameters + return c.Parameters } -func (s *EnvSpec) GetConfigRefs() []string { return s.ConfigRefs } +func (c *ConfigSpec) GetConfigRefs() []string { return c.ConfigRefs } -func (s *EnvSpec) SetConfigRefs(refs []string) { s.ConfigRefs = refs } +func (c *ConfigSpec) SetConfigRefs(refs []string) { c.ConfigRefs = refs } -func (s *EnvSpec) GetSecretRefs() []string { return s.SecretRefs } +func (c *ConfigSpec) GetSecretRefs() []string { return c.SecretRefs } -func (s *EnvSpec) SetSecretRefs(refs []string) { s.SecretRefs = refs } +func (c *ConfigSpec) SetSecretRefs(refs []string) { c.SecretRefs = refs } -func (e *EnvSpec) GetEnvFrom() []corev1.EnvFromSource { +func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { envFroms := []corev1.EnvFromSource{} envFrom := corev1.EnvFromSource{} - for _, p := range *e.Parameters { + for _, p := range *c.Parameters { if len(p.Ref) > 0 { - if p.MountType == MountEnvFile { - if p.Type == ConfigParameter { - e.ConfigRefs = append(e.ConfigRefs, p.Ref) - } else if p.Type != ObjectFieldParameter { - e.SecretRefs = append(e.SecretRefs, p.Ref) + if p.MountType == parameters.MountEnvFile { + if p.Type == parameters.ConfigParameter { + c.ConfigRefs = append(c.ConfigRefs, p.Ref) + } else if p.Type != parameters.ObjectFieldParameter { + c.SecretRefs = append(c.SecretRefs, p.Ref) } } } } - e.SecretRefs = utils.Unique(e.SecretRefs) - e.ConfigRefs = utils.Unique(e.ConfigRefs) + c.SecretRefs = utils.Unique(c.SecretRefs) + c.ConfigRefs = utils.Unique(c.ConfigRefs) - if len(e.ConfigRefs) > 0 { - for _, configRef := range e.ConfigRefs { + if len(c.ConfigRefs) > 0 { + for _, configRef := range c.ConfigRefs { envFrom = corev1.EnvFromSource{ ConfigMapRef: &corev1.ConfigMapEnvSource{ LocalObjectReference: corev1.LocalObjectReference{ @@ -75,8 +76,8 @@ func (e *EnvSpec) GetEnvFrom() []corev1.EnvFromSource { } } - if len(e.SecretRefs) > 0 { - for _, secretRef := range e.SecretRefs { + if len(c.SecretRefs) > 0 { + for _, secretRef := range c.SecretRefs { envFrom = corev1.EnvFromSource{ SecretRef: &corev1.SecretEnvSource{ LocalObjectReference: corev1.LocalObjectReference{ @@ -97,7 +98,7 @@ func (e *EnvSpec) GetEnvFrom() []corev1.EnvFromSource { // We need to manually change this autogenerated function as it is broken with Paramete drs type, its trying to do new([]*Parameter) instead of new(Parameters) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *EnvSpec) DeepCopyInto(out *EnvSpec) { +func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) { *out = *in if in.SecretRefs != nil { in, out := &in.SecretRefs, &out.SecretRefs @@ -111,17 +112,17 @@ func (in *EnvSpec) DeepCopyInto(out *EnvSpec) { } if in.Parameters != nil { in, out := &in.Parameters, &out.Parameters - *out = new(Parameters) + *out = new(parameters.Parameters) (*in).DeepCopyInto(*out) } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. -func (in *EnvSpec) DeepCopy() *EnvSpec { +func (in *ConfigSpec) DeepCopy() *ConfigSpec { if in == nil { return nil } - out := new(EnvSpec) + out := new(ConfigSpec) in.DeepCopyInto(out) return out } diff --git a/settings/interface.go b/application/settings/interface.go similarity index 84% rename from settings/interface.go rename to application/settings/interface.go index 9952e40..e786c52 100644 --- a/settings/interface.go +++ b/application/settings/interface.go @@ -15,18 +15,20 @@ limitations under the License. package settings -type Env interface { +import "k8s.libre.sh/application/settings/parameters" + +type Config interface { GetConfigRefs() []string SetConfigRefs([]string) - GetParameters() *Parameters - SetParameters(*Parameters) + GetParameters() *parameters.Parameters + SetParameters(*parameters.Parameters) GetSecretRefs() []string SetSecretRefs([]string) InitRandValues() InitTemplateValues(map[string]string) error } -func MergeSettings(src, dest Env) Env { +func MergeSettings(src, dest Config) Config { if dest == nil { dest = src diff --git a/settings/parameter.go b/application/settings/parameters/parameter.go similarity index 99% rename from settings/parameter.go rename to application/settings/parameters/parameter.go index 9a00e8a..fbc4729 100644 --- a/settings/parameter.go +++ b/application/settings/parameters/parameter.go @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package settings +package parameters const ( GenerateRand Generate = "rand" diff --git a/settings/parameter_helper.go b/application/settings/parameters/parameter_helper.go similarity index 99% rename from settings/parameter_helper.go rename to application/settings/parameters/parameter_helper.go index f84e02e..d92b413 100644 --- a/settings/parameter_helper.go +++ b/application/settings/parameters/parameter_helper.go @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package settings +package parameters import ( "errors" diff --git a/settings/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go similarity index 65% rename from settings/parameters_helpers.go rename to application/settings/parameters/parameters_helpers.go index 15366fd..7a9e9fd 100644 --- a/settings/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -13,14 +13,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -package settings +package parameters import ( "bytes" + "context" "text/template" "github.com/presslabs/controller-util/rand" corev1 "k8s.io/api/core/v1" + "k8s.libre.sh/interfaces" + "sigs.k8s.io/controller-runtime/pkg/client" ) func (p *Parameters) InitValues() { @@ -89,7 +92,7 @@ func (p *Parameters) GetData() map[string]string { return data } -func (p *Parameters) GetEnv() []corev1.EnvVar { +func (p *Parameters) GetConfig() []corev1.EnvVar { envVars := []corev1.EnvVar{} envVar := corev1.EnvVar{} @@ -111,3 +114,45 @@ func (p *Parameters) GetEnv() []corev1.EnvVar { } return nil } + +func GetAndMergeParameters(params Parameters, paramsByKey map[string]*Parameter, c client.Client, obj interfaces.Object) error { + + objectKey, _ := client.ObjectKeyFromObject(obj) + + err := c.Get(context.Background(), objectKey, obj) + + if err != nil { + return err + } + + data := map[string]string{} + + if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { + for k, v := range obj.(*corev1.Secret).Data { + data[k] = string(v) + } + } + if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { + for k, v := range obj.(*corev1.ConfigMap).Data { + data[k] = v + } + } + + if len(params) > 0 { + for _, pp := range params { + paramsByKey[pp.Key].Value = string(data[pp.FromKey]) + } + } else { + for kk, vv := range data { + if paramsByKey[kk] == nil { + paramsByKey[kk] = new(Parameter) + } + paramsByKey[kk].Value = vv + paramsByKey[kk].Key = kk + // TODO This would be checked if we want to recreate the data or juste mount the whole secret + paramsByKey[kk].MountType = MountEnvFile + } + } + + return nil +} diff --git a/settings/parameters_suite_test.go b/application/settings/parameters/parameters_suite_test.go similarity index 88% rename from settings/parameters_suite_test.go rename to application/settings/parameters/parameters_suite_test.go index cae0084..3ebdba6 100644 --- a/settings/parameters_suite_test.go +++ b/application/settings/parameters/parameters_suite_test.go @@ -1,4 +1,4 @@ -package settings_test +package parameters_test import ( "testing" diff --git a/settings/parameters_test.go b/application/settings/parameters/parameters_test.go similarity index 69% rename from settings/parameters_test.go rename to application/settings/parameters/parameters_test.go index ede86f5..2511225 100644 --- a/settings/parameters_test.go +++ b/application/settings/parameters/parameters_test.go @@ -1,10 +1,10 @@ -package settings_test +package parameters_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - . "k8s.libre.sh/settings" + . "k8s.libre.sh/application/settings/parameters" corev1 "k8s.io/api/core/v1" ) @@ -24,8 +24,8 @@ var _ = Describe("Parameters", func() { valueFromSecret ValueFrom valueFromObject ValueFrom parameters *Parameters - settings *Settings - envFrom *EnvFrom + // settings *Settings + // envFrom *EnvFrom ) BeforeEach(func() { @@ -43,7 +43,7 @@ var _ = Describe("Parameters", func() { Value: "{{ .LITERAL_PARAMETER }}", Type: ConfigParameter, Generate: GenerateTemplate, - MountType: MountFrom, + MountType: MountEnvFile, } paramEnvVar = Parameter{ @@ -82,24 +82,6 @@ var _ = Describe("Parameters", func() { MountType: MountFrom, } - // TODO THIS SHOULD THROW AN ERROR - - // paramEnvFrom = Parameter{ - // ValueFrom: ValueFrom{ - // Ref: "confgRef", - // }, - // Type: ConfigParameter, - // MountType: MountFrom, - // } - - // paramEnvFromSecret = Parameter{ - // ValueFrom: ValueFrom{ - // Ref: "secretRef", - // }, - // Type: SecretParameter, - // MountType: MountFrom, - // } - paramEnvVarFromObject = Parameter{ Key: "PARAMETER_FROM_OBJECT", Type: ObjectFieldParameter, @@ -130,20 +112,20 @@ var _ = Describe("Parameters", func() { ¶mMountFile, } - envFrom = &EnvFrom{ - SecretRefs: []string{ - "mysecret", - "myothersecret", - }, - ConfigRefs: []string{ - "myconfigmap", - }, - } - - settings = &Settings{ - EnvFrom: envFrom, - Parameters: parameters, - } + /* envFrom = &EnvFrom{ + SecretRefs: []string{ + "mysecret", + "myothersecret", + }, + ConfigRefs: []string{ + "myconfigmap", + }, + } + + settings = &Settings{ + EnvFrom: envFrom, + Parameters: parameters, + } */ }) @@ -207,7 +189,7 @@ var _ = Describe("Parameters", func() { }) }) - Describe("Generating Env for containers with EnvFrom", func() { + /* Describe("Generating Env for containers with EnvFrom", func() { Context("Generating env", func() { It("should generate envFrom", func() { @@ -241,74 +223,78 @@ var _ = Describe("Parameters", func() { // Expect(err).NotTo(HaveOccurred()) }) }) - Describe("Generating Env for containers with Parameters", func() { - Context("Generating envFrom", func() { - It("should generate envVar", func() { - - expectedObj := []corev1.EnvVar{ - { - Name: "LITERAL_PARAMETER", - Value: "LiteralParameter", - }, - { - Name: "VALUE_FROM_CONFIG_PARAMETER", - ValueFrom: &corev1.EnvVarSource{ - ConfigMapKeyRef: &corev1.ConfigMapKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "configRef", - }, - Key: "FROM_KEY_CONFIG_PARAMETER", + }) */ + + Describe("Generating Env for containers with Parameters", func() { + Context("Generating envFrom", func() { + It("should generate envVar", func() { + + expectedObj := []corev1.EnvVar{ + { + Name: "LITERAL_PARAMETER", + Value: "LiteralParameter", + }, + { + Name: "VALUE_FROM_CONFIG_PARAMETER", + ValueFrom: &corev1.EnvVarSource{ + ConfigMapKeyRef: &corev1.ConfigMapKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "configRef", }, + Key: "FROM_KEY_CONFIG_PARAMETER", }, }, - { - Name: "VALUE_FROM_SECRET_PARAMETER", - ValueFrom: &corev1.EnvVarSource{ - SecretKeyRef: &corev1.SecretKeySelector{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: "secretRef", - }, - Key: "FROM_KEY_SECRET_PARAMETER", + }, + { + Name: "VALUE_FROM_SECRET_PARAMETER", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "secretRef", }, + Key: "FROM_KEY_SECRET_PARAMETER", }, }, - { - Name: "PARAMETER_FROM_OBJECT", - ValueFrom: &corev1.EnvVarSource{ - FieldRef: &corev1.ObjectFieldSelector{ - APIVersion: "v1", - FieldPath: "status.podIP", - }, + }, + { + Name: "PARAMETER_FROM_OBJECT", + ValueFrom: &corev1.EnvVarSource{ + FieldRef: &corev1.ObjectFieldSelector{ + APIVersion: "v1", + FieldPath: "status.podIP", }, }, - { - Name: "TEMPLATE_PARAMETER", - Value: "LiteralParameter", - }, - } + }, + { + Name: "TEMPLATE_PARAMETER", + Value: "LiteralParameter", + }, + } - parameters.InitValues() - res := parameters.GetEnv() + parameters.InitValues() + res := parameters.GetConfig() - Expect(res).To(Equal(expectedObj)) - // Expect(err).NotTo(HaveOccurred()) - }) + Expect(res).To(Equal(expectedObj)) + // Expect(err).NotTo(HaveOccurred()) }) }) - Describe("Generating data for configmap and secret with Parameters", func() { - Context("Generating data", func() { - It("should generate data", func() { - parameters.InitValues() + }) - expectedObj := map[string]string{ - "TEMPLATE_PARAMETER_FROM": "LiteralParameter", - } + Describe("Generating data for configmap and secret with Parameters", func() { + Context("Generating data", func() { + It("should generate data", func() { + parameters.InitValues() - Expect(parameters.GetConfigData()).To(Equal(expectedObj)) - // Expect(err).NotTo(HaveOccurred()) - }) + expectedObj := map[string]string{ + "TEMPLATE_PARAMETER_FROM": "LiteralParameter", + } + + Expect(parameters.GetData()).To(Equal(expectedObj)) + // Expect(err).NotTo(HaveOccurred()) }) }) + }) + /* Describe("Generating mount files", func() { Context("Generating volumes & volume mount", func() { It("should generate volume for pod", func() { @@ -339,5 +325,6 @@ var _ = Describe("Parameters", func() { }) }) }) - }) + */ + }) diff --git a/settings/utils.go b/application/settings/parameters/utils.go similarity index 62% rename from settings/utils.go rename to application/settings/parameters/utils.go index 36885cd..ca74d0a 100644 --- a/settings/utils.go +++ b/application/settings/parameters/utils.go @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package settings +package parameters import ( "reflect" @@ -32,6 +32,7 @@ func Marshal(i interface{}) (Parameters, error) { fv := ifv.Field(ii) parameter, ok := fv.Interface().(Parameter) + // TODO Return error if !ok { // return nil, ok } @@ -65,31 +66,6 @@ func ParametersByKey(p *Parameters) map[string]*Parameter { return paramsByKey } -func OrderByResourceRef(s *EnvSpec) (secrets, configs map[string]Parameters) { - secrets = make(map[string]Parameters) - configs = make(map[string]Parameters) - - // We order the parameters by secret and configmap sources - // First we get the sources provided as resources that should be mounted untouched - for _, ref := range s.SecretRefs { - secrets[ref] = Parameters{} - } - for _, ref := range s.ConfigRefs { - configs[ref] = Parameters{} - } - - // Then we get the sources that are provided for each parameters and will need a transformation - for _, p := range *s.Parameters { - if len(p.ValueFrom.Ref) > 0 && p.Type == SecretParameter { - secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p) - } - if len(p.ValueFrom.Ref) > 0 && p.Type == ConfigParameter { - configs[p.ValueFrom.Ref] = append(configs[p.ValueFrom.Ref], p) - } - } - return secrets, configs -} - func KeyPairValues(p *Parameters) map[string]string { data := make(map[string]string) diff --git a/settings/zz_generated.deepcopy.go b/application/settings/parameters/zz_generated.deepcopy.go similarity index 98% rename from settings/zz_generated.deepcopy.go rename to application/settings/parameters/zz_generated.deepcopy.go index 1a04750..7bf5882 100644 --- a/settings/zz_generated.deepcopy.go +++ b/application/settings/parameters/zz_generated.deepcopy.go @@ -17,7 +17,7 @@ limitations under the License. // Code generated by controller-gen. DO NOT EDIT. -package settings +package parameters import () diff --git a/application/settings/utils.go b/application/settings/utils.go new file mode 100644 index 0000000..a4ce037 --- /dev/null +++ b/application/settings/utils.go @@ -0,0 +1,43 @@ +/* + +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 settings + +import "k8s.libre.sh/application/settings/parameters" + +func OrderByResourceRef(s *ConfigSpec) (secrets, configs map[string]parameters.Parameters) { + secrets = make(map[string]parameters.Parameters) + configs = make(map[string]parameters.Parameters) + + // We order the parameters by secret and configmap sources + // First we get the sources provided as resources that should be mounted untouched + for _, ref := range s.SecretRefs { + secrets[ref] = parameters.Parameters{} + } + for _, ref := range s.ConfigRefs { + configs[ref] = parameters.Parameters{} + } + + // Then we get the sources that are provided for each parameters and will need a transformation + for _, p := range *s.Parameters { + if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.SecretParameter { + secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p) + } + if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.ConfigParameter { + configs[p.ValueFrom.Ref] = append(configs[p.ValueFrom.Ref], p) + } + } + return secrets, configs +} diff --git a/cover.out b/cover.out new file mode 100644 index 0000000..40f4c45 --- /dev/null +++ b/cover.out @@ -0,0 +1,88 @@ +mode: set +k8s.libre.sh/application/settings/parameters/utils.go:22.49,29.39 4 0 +k8s.libre.sh/application/settings/parameters/utils.go:56.2,56.24 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:29.39,36.10 4 0 +k8s.libre.sh/application/settings/parameters/utils.go:40.3,41.10 2 0 +k8s.libre.sh/application/settings/parameters/utils.go:45.3,45.30 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:49.3,49.36 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:53.3,53.46 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:36.11,38.4 0 0 +k8s.libre.sh/application/settings/parameters/utils.go:41.11,43.4 0 0 +k8s.libre.sh/application/settings/parameters/utils.go:45.30,47.4 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:49.36,51.4 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:59.59,62.23 2 0 +k8s.libre.sh/application/settings/parameters/utils.go:66.2,66.20 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:62.23,64.3 1 0 +k8s.libre.sh/application/settings/parameters/utils.go:69.53,72.27 2 1 +k8s.libre.sh/application/settings/parameters/utils.go:76.2,76.13 1 1 +k8s.libre.sh/application/settings/parameters/utils.go:72.27,74.3 1 1 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:25.51,29.2 3 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:32.44,33.15 1 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:36.2,38.12 3 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:33.15,35.3 1 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:42.52,43.2 1 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:43.2,46.22 3 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:46.22,47.23 1 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:47.23,51.5 3 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:57.44,58.15 1 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:61.2,63.13 3 0 +k8s.libre.sh/application/settings/parameters/zz_generated.deepcopy.go:58.15,60.3 1 0 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:24.67,26.21 1 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:28.20,29.41 1 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:36.3,36.65 1 0 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:38.17,39.61 1 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:82.3,82.49 1 0 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:84.10,85.47 1 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:29.41,35.4 2 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:39.61,40.18 1 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:41.25,53.23 2 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:55.25,67.23 2 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:69.30,79.23 2 1 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:89.51,91.2 1 0 +k8s.libre.sh/application/settings/parameters/parameter_helper.go:93.58,95.2 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:29.35,32.2 2 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:34.39,35.27 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:35.27,37.126 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:37.126,39.26 2 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:40.24,43.19 3 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:45.5,45.25 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:47.24,50.19 3 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:52.5,52.25 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:43.20,44.6 0 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:50.20,51.6 0 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:58.73,60.27 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:78.2,78.12 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:60.27,61.41 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:61.41,64.18 2 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:68.4,71.18 3 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:75.4,75.30 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:64.18,66.5 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:71.18,73.5 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:81.50,84.27 2 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:92.2,92.13 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:84.27,87.25 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:87.25,89.4 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:95.50,101.27 4 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:112.2,112.22 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:115.2,115.12 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:101.27,104.17 2 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:107.3,107.27 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:104.18,105.4 0 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:107.27,109.4 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:112.22,114.3 1 1 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:118.128,124.16 3 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:128.2,130.61 2 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:135.2,135.64 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:141.2,141.21 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:157.2,157.12 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:124.16,126.3 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:130.61,131.47 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:131.47,133.4 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:135.64,136.50 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:136.50,138.4 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:141.21,142.29 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:142.29,144.4 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:145.8,146.28 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:146.28,147.30 1 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:150.4,153.44 3 0 +k8s.libre.sh/application/settings/parameters/parameters_helpers.go:147.30,149.5 1 0 diff --git a/instance/instance.go b/instance/instance.go deleted file mode 100644 index 905a661..0000000 --- a/instance/instance.go +++ /dev/null @@ -1,211 +0,0 @@ -package instance - -import ( - "context" - - "github.com/presslabs/controller-util/syncer" - interfaces "k8s.libre.sh/interfaces" - meta "k8s.libre.sh/meta" - parameters "k8s.libre.sh/settings" - "sigs.k8s.io/controller-runtime/pkg/client" - - corev1 "k8s.io/api/core/v1" -) - -type Instance interface { - meta.Instance - GetComponents() map[int]Component - GetOwner() interfaces.Object - GetSettings() Settings - SetDefaults() -} - -func Init(i Instance) { - - i.SetDefaults() - - for _, c := range i.GetComponents() { - c.Init() - - // TODO TOFIX - component := c.GetComponent() - - meta.SetObjectMeta(i, c) - - if len(component) > 0 { - c.SetComponent(component) - } - - for _, o := range c.GetObjects() { - meta.SetObjectMeta(c, o) - } - - c.SetDefaults() - - } - -} - -func NewSyncers(app Instance, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface) { - - ///////////////////// - //// Settings ////// - /////////////////// - - // INITIALISE VALUES FROM EXTERNAL RESOURCES, RANDOM & TEMPLATES - sett := app.GetSettings().GetEnv().(*parameters.Settings) - - err := InitParametersValueFrom(sett, app.GetSettings().GetMeta(), r) - - if err != nil { - // return ctrl.Result{}, err - } - - sett.InitRandValues() - - err = sett.InitTemplateValues(parameters.KeyPairValues(sett.Parameters)) - - if err != nil { - // return nil, err - } - - // Object Syncers - objects := GetObjects(sett) - - for _, obj := range objects { - s := NewObjectSyncer(obj, owner, r) - - if err := syncer.Sync(context.TODO(), s, r.GetRecorder()); err != nil { - // return nil, err - } - - } - - ///////////////////// - //// Components //// - /////////////////// - components := app.GetComponents() - - // INITIALIZE - for _, c := range components { - - component := c.GetComponent() - - meta.SetObjectMeta(app, c) - - if len(component) > 0 { - c.SetComponent(component) - } - - if c.HasDependencies() { - - settings := c.GetDependencies() - settings = parameters.MergeSettings(sett, settings) - - } - // GET SYNCERS - mutators := c.GetObjects() - for _, m := range mutators { - meta.SetObjectMeta(c, m) - syncers = append(syncers, NewObjectSyncer(m, owner, r)) - } - } - return syncers - -} - -func GetAndMergeParameters(params parameters.Parameters, paramsByKey map[string]*parameters.Parameter, r interfaces.Reconcile, obj interfaces.Object) error { - - objectKey, _ := client.ObjectKeyFromObject(obj) - - err := r.GetClient().Get(context.Background(), objectKey, obj) - - if err != nil { - return err - } - - data := map[string]string{} - - if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { - for k, v := range obj.(*corev1.Secret).Data { - data[k] = string(v) - } - } - if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { - for k, v := range obj.(*corev1.ConfigMap).Data { - data[k] = v - } - } - - if len(params) > 0 { - for _, pp := range params { - paramsByKey[pp.Key].Value = string(data[pp.FromKey]) - } - } else { - for kk, vv := range data { - if paramsByKey[kk] == nil { - paramsByKey[kk] = new(parameters.Parameter) - } - paramsByKey[kk].Value = vv - paramsByKey[kk].Key = kk - // TODO This would be checked if we want to recreate the data or juste mount the whole secret - paramsByKey[kk].MountType = parameters.MountEnvFile - } - } - - return nil -} - -// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace -// All parameters values are filled from those resources -func InitParametersValueFrom(s *parameters.Settings, m meta.Meta, r interfaces.Reconcile) error { - // params := s.GetParameters().(*parameters.Settings) - - params := parameters.Parameters{} - - paramsByKey := parameters.ParametersByKey(s.Parameters) - paramsBySecretSource, paramsByConfigMapSource := parameters.OrderByResourceRef(s) - - cm := &corev1.ConfigMap{} - sec := &corev1.Secret{} - - cm.SetNamespace(m.GetNamespace()) - sec.SetNamespace(m.GetNamespace()) - - // We get the secrets - for k, v := range paramsBySecretSource { - sec.SetName(k) - - err := GetAndMergeParameters(v, paramsByKey, r, sec) - if err != nil { - return err - } - } - - for k, v := range paramsByConfigMapSource { - cm.SetName(k) - err := GetAndMergeParameters(v, paramsByKey, r, sec) - if err != nil { - return err - } - } - - for _, v := range paramsByKey { - if v.MountType == parameters.MountEnvFile { - if v.Type == parameters.ConfigParameter { - v.Ref = s.GetConfigMapMeta().GetName() - } - if v.Type == parameters.SecretParameter { - v.Ref = s.GetSecretMeta().GetName() - } - } - params = append(params, v) - } - - // TODO FIX THIS we need to check if we want to mount as EnvFile and reset old resources references - s.SecretRefs = []string{} - s.ConfigRefs = []string{} - s.Parameters = ¶ms - - return nil -} diff --git a/objects/configmap/object.go b/objects/configmap/object.go index 116e5bf..e0226cb 100644 --- a/objects/configmap/object.go +++ b/objects/configmap/object.go @@ -16,9 +16,9 @@ limitations under the License. package configmap import ( + parameters "k8s.libre.sh/application/settings/parameters" interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" - parameters "k8s.libre.sh/settings" corev1 "k8s.io/api/core/v1" ) diff --git a/objects/configmap/zz_generated.deepcopy.go b/objects/configmap/zz_generated.deepcopy.go index b63153f..aa97cb0 100644 --- a/objects/configmap/zz_generated.deepcopy.go +++ b/objects/configmap/zz_generated.deepcopy.go @@ -20,8 +20,8 @@ limitations under the License. package configmap import ( + "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/meta" - "k8s.libre.sh/settings" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -34,11 +34,11 @@ func (in *ConfigMap) DeepCopyInto(out *ConfigMap) { } if in.Parameters != nil { in, out := &in.Parameters, &out.Parameters - *out = make(settings.Parameters, len(*in)) + *out = make(parameters.Parameters, len(*in)) for i := range *in { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] - *out = new(settings.Parameter) + *out = new(parameters.Parameter) **out = **in } } diff --git a/objects/container/mutate.go b/objects/container/mutate.go index 6dc1d38..af36fe0 100644 --- a/objects/container/mutate.go +++ b/objects/container/mutate.go @@ -23,8 +23,7 @@ type Mutate interface { // Parameters // GetVolumeMount() []corev1.VolumeMount GetEnvFrom() []corev1.EnvFromSource - GetEnv() []corev1.EnvVar - // GetParameters() parameters.Parameters + GetConfig() []corev1.EnvVar // Runtime GetContainerName() string GetContainerImage() string @@ -45,7 +44,7 @@ func MutateContainer(r Mutate, obj *corev1.Container) error { obj.Args = r.GetContainerArgs() obj.EnvFrom = r.GetEnvFrom() - obj.Env = r.GetEnv() + obj.Env = r.GetConfig() // obj.VolumeMounts = r.GetVolumeMount() diff --git a/objects/container/object.go b/objects/container/object.go index a202ac0..3fa44da 100644 --- a/objects/container/object.go +++ b/objects/container/object.go @@ -17,13 +17,13 @@ package container import ( corev1 "k8s.io/api/core/v1" - parameters "k8s.libre.sh/settings" + parameters "k8s.libre.sh/application/settings" ) // +kubebuilder:object:generate=true type Container struct { - *TemplateSpec `json:",inline"` - *parameters.EnvSpec `json:"parameters,omitempty"` + *TemplateSpec `json:",inline"` + *parameters.ConfigSpec `json:"parameters,omitempty"` } // +kubebuilder:object:generate=true diff --git a/objects/container/zz_generated.deepcopy.go b/objects/container/zz_generated.deepcopy.go index 7000ead..edd432f 100644 --- a/objects/container/zz_generated.deepcopy.go +++ b/objects/container/zz_generated.deepcopy.go @@ -31,8 +31,8 @@ func (in *Container) DeepCopyInto(out *Container) { *out = new(TemplateSpec) (*in).DeepCopyInto(*out) } - if in.EnvSpec != nil { - in, out := &in.EnvSpec, &out.EnvSpec + if in.ConfigSpec != nil { + in, out := &in.ConfigSpec, &out.ConfigSpec *out = (*in).DeepCopy() } } diff --git a/instance/object.go b/objects/object.go similarity index 98% rename from instance/object.go rename to objects/object.go index 3a5fd59..d529f3e 100644 --- a/instance/object.go +++ b/objects/object.go @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package instance +package objects import ( interfaces "k8s.libre.sh/interfaces" diff --git a/objects/pod/pod_suite_test.go b/objects/pod/pod_suite_test.go deleted file mode 100644 index 56d1091..0000000 --- a/objects/pod/pod_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package pod_test - -import ( - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -func TestPod(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Pod Suite") -} diff --git a/objects/pod/pod_test.go b/objects/pod/pod_test.go deleted file mode 100644 index fe65bf0..0000000 --- a/objects/pod/pod_test.go +++ /dev/null @@ -1,75 +0,0 @@ -package pod_test - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - - "k8s.libre.sh/meta" - container "k8s.libre.sh/objects/container" - . "k8s.libre.sh/objects/pod" - parameters "k8s.libre.sh/settings" - - corev1 "k8s.io/api/core/v1" -) - -var _ = Describe("Pod", func() { - Describe("Mutate Pod", func() { - Context("With a single container", func() { - It("should generate pod with single container", func() { - - pod := Pod{ - PodSpec: &PodSpec{ - ObjectMeta: &meta.ObjectMeta{ - Name: "test", - Namespace: "test", - // Labels: - }, - // Resources: corev1.ResourceRequirements{}, - // SecurityContext: &corev1.PodSecurityContext{}, - // Affinity: &corev1.Affinity{}, - // RestartPolicy: "restart", - // Tolerations: []corev1.Toleration{}, - // NodeSelector: map[string]string{}, - Container: container.Container{ - TemplateSpec: &container.TemplateSpec{ - Name: "mycontainer", - }, - Settings: parameters.Settings{ - // TODO FIX PARAMETERS HAS TO BE INITIALIZE OR NIL POINTER RECEIVER ERROR - // ENVFROM & ENV returns empty array it should return nil - Parameters: new(parameters.Parameters), - }, - }, - // ExtraContainers: []container.Container{}, - // InitContainers: []container.Container{}, - }, - } - - // initialObject := &corev1.Pod{ - // Spec: corev1.PodSpec{ - // Containers: []corev1.Container{ - // corev1.Container{ - // Name: "mycontainer", - // }, - // }, - // }, - // } - - initialObject := &corev1.PodTemplateSpec{} - - expectedObj := corev1.PodSpec{ - Containers: []corev1.Container{ - corev1.Container{ - Name: "mycontainer", - }, - }, - } - - err := MutatePod(pod, initialObject) - - Expect(initialObject.Spec).To(Equal(expectedObj)) - Expect(err).NotTo(HaveOccurred()) - }) - }) - }) -}) diff --git a/objects/secret/object.go b/objects/secret/object.go index 71e85e3..2b37e0d 100644 --- a/objects/secret/object.go +++ b/objects/secret/object.go @@ -16,9 +16,9 @@ limitations under the License. package secret import ( + settings "k8s.libre.sh/application/settings/parameters" interfaces "k8s.libre.sh/interfaces" meta "k8s.libre.sh/meta" - settings "k8s.libre.sh/settings" corev1 "k8s.io/api/core/v1" ) diff --git a/objects/secret/zz_generated.deepcopy.go b/objects/secret/zz_generated.deepcopy.go index 6a43562..7b34f57 100644 --- a/objects/secret/zz_generated.deepcopy.go +++ b/objects/secret/zz_generated.deepcopy.go @@ -20,8 +20,8 @@ limitations under the License. package secret import ( + "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/meta" - "k8s.libre.sh/settings" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -34,11 +34,11 @@ func (in *Secret) DeepCopyInto(out *Secret) { } if in.Parameters != nil { in, out := &in.Parameters, &out.Parameters - *out = make(settings.Parameters, len(*in)) + *out = make(parameters.Parameters, len(*in)) for i := range *in { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] - *out = new(settings.Parameter) + *out = new(parameters.Parameter) **out = **in } } diff --git a/objects/service/mutate.go b/objects/service/mutate.go index 9b1778b..49d6d31 100644 --- a/objects/service/mutate.go +++ b/objects/service/mutate.go @@ -1,8 +1,8 @@ package service import ( - meta "k8s.libre.sh/meta" corev1 "k8s.io/api/core/v1" + meta "k8s.libre.sh/meta" ) type Mutate interface { diff --git a/settings/settings.go b/settings/settings.go deleted file mode 100644 index 84f8d29..0000000 --- a/settings/settings.go +++ /dev/null @@ -1,41 +0,0 @@ -/* - -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 settings - -import ( - "k8s.libre.sh/meta" -) - -// +kubebuilder:object:generate=true -type Settings struct { - CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` - SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` - ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` - *EnvSpec `json:",inline"` -} - -func (s *Settings) GetEnv() Env { return s.EnvSpec } - -func (s *Settings) GetMeta() meta.Instance { return s.CommonMeta } - -func (s *Settings) GetSecretMeta() meta.Instance { return s.SecretMeta } - -func (s *Settings) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } - -func (s *Settings) SetDefaults() { - meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) - meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) -} -- GitLab From 7ec94e701bb5f9e55cf11fcd7ff094882873d96e Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Tue, 19 May 2020 01:57:23 +0200 Subject: [PATCH 03/18] add doc --- application/component.go | 1 - application/components/network.go | 1 + application/components/settings.go | 34 +++++----- .../components/zz_generated.deepcopy.go | 36 ++++++++++- application/instance.go | 1 - application/settings/config.go | 13 +++- application/settings/parameters/parameter.go | 50 ++++++++++----- .../settings/parameters/parameter_helper.go | 2 +- .../settings/parameters/parameters_helpers.go | 28 +++++++-- .../settings/parameters/parameters_test.go | 2 +- application/settings/parameters/utils.go | 7 ++- objects/container/mutate.go | 4 +- objects/container/object.go | 61 +++++++++++++++--- objects/container/zz_generated.deepcopy.go | 5 -- objects/pod/object.go | 63 ++++++++++++++++--- objects/pod/zz_generated.deepcopy.go | 5 ++ objects/service/object.go | 26 +++++++- 17 files changed, 267 insertions(+), 72 deletions(-) diff --git a/application/component.go b/application/component.go index e95669d..4482647 100644 --- a/application/component.go +++ b/application/component.go @@ -16,7 +16,6 @@ type Component interface { GetObjects() map[int]objects.Object HasDependencies() bool GetDependencies() settings.Config - // SetDependencies(*parameters.Settings) } func NewSyncer(i Component, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface) { diff --git a/application/components/network.go b/application/components/network.go index 601a7e0..50f4521 100644 --- a/application/components/network.go +++ b/application/components/network.go @@ -29,6 +29,7 @@ import ( service "k8s.libre.sh/objects/service" ) +// +kubebuilder:object:generate=true type Network struct { IngressMeta *meta.ObjectMeta `json:"ingressMeta,omitempty"` ServiceMeta *meta.ObjectMeta `json:"serviceMeta,omitempty"` diff --git a/application/components/settings.go b/application/components/settings.go index ab1d060..85c715d 100644 --- a/application/components/settings.go +++ b/application/components/settings.go @@ -29,9 +29,12 @@ import ( // +kubebuilder:object:generate=true type Settings struct { - CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` - SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` - ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` + SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` + ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + DefaultType parameters.ParameterType `json:"defaultType,omitempty"` + DefaultMountType parameters.MountType `json:"defaultMountType,omitempty"` + // Template string `json:"template,omitempty"` *settings.ConfigSpec `json:",inline"` } @@ -44,6 +47,7 @@ func (s *Settings) GetSecretMeta() meta.Instance { return s.SecretMeta } func (s *Settings) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } func (s *Settings) SetDefaults() { + // TODO TO FIX DUPLICATE WITH INIT meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) } @@ -60,13 +64,13 @@ func (s *Settings) GetObjects() map[int]objects.Object { objs := make(map[int]objects.Object, 2) - meta.SetObjectMeta(s.CommonMeta, cm.ObjectMeta) - meta.SetObjectMeta(s.CommonMeta, secret.ObjectMeta) + // meta.SetObjectMeta(s.CommonMeta, cm.ObjectMeta) + // meta.SetObjectMeta(s.CommonMeta, secret.ObjectMeta) // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS - params := s.GetConfig() + // params := s.GetConfig() - for _, p := range *params.GetParameters() { + for _, p := range *s.ConfigSpec.GetParameters() { // TODO check not mountLiteral ?? if p.MountType == parameters.MountEnvFile && p.Type == parameters.SecretParameter && @@ -80,7 +84,7 @@ func (s *Settings) GetObjects() map[int]objects.Object { } } - // TODO IMPROVEparameeters + // TODO IMPROVE if len(cm.Parameters) > 0 { objs[0] = cm } @@ -99,9 +103,10 @@ func (s *Settings) GetObjects() map[int]objects.Object { } func (s *Settings) Init(c client.Client) error { - + // TODO TO FIX DUPLICATE WITH SETDEFAULTS + meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) + meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) // TODO ADD SECRET REFS HERE ?? - err := InitParametersValueFrom(s, c) if err != nil { @@ -118,7 +123,6 @@ func (s *Settings) Init(c client.Client) error { // InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace // All parameters values are filled from those resources func InitParametersValueFrom(s *Settings, c client.Client) error { - // params := s.GetParameters().(*parameters.Settings) params := parameters.Parameters{} @@ -131,10 +135,8 @@ func InitParametersValueFrom(s *Settings, c client.Client) error { cm.SetNamespace(s.CommonMeta.GetNamespace()) sec.SetNamespace(s.CommonMeta.GetNamespace()) - // We get the secrets for k, v := range paramsBySecretSource { sec.SetName(k) - err := parameters.GetAndMergeParameters(v, paramsByKey, c, sec) if err != nil { return err @@ -143,7 +145,7 @@ func InitParametersValueFrom(s *Settings, c client.Client) error { for k, v := range paramsByConfigMapSource { cm.SetName(k) - err := parameters.GetAndMergeParameters(v, paramsByKey, c, sec) + err := parameters.GetAndMergeParameters(v, paramsByKey, c, cm) if err != nil { return err } @@ -161,9 +163,13 @@ func InitParametersValueFrom(s *Settings, c client.Client) error { params = append(params, v) } + // if defaultMountType == EnvFile { + + // } // TODO FIX THIS we need to check if we want to mount as EnvFile and reset old resources references s.SecretRefs = []string{} s.ConfigRefs = []string{} + s.Parameters = ¶ms return nil diff --git a/application/components/zz_generated.deepcopy.go b/application/components/zz_generated.deepcopy.go index 30bad83..c499360 100644 --- a/application/components/zz_generated.deepcopy.go +++ b/application/components/zz_generated.deepcopy.go @@ -45,6 +45,36 @@ func (in *Backend) DeepCopy() *Backend { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Network) DeepCopyInto(out *Network) { + *out = *in + if in.IngressMeta != nil { + in, out := &in.IngressMeta, &out.IngressMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) + } + if in.ServiceMeta != nil { + in, out := &in.ServiceMeta, &out.ServiceMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) + } + if in.Backend != nil { + in, out := &in.Backend, &out.Backend + *out = new(Backend) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Network. +func (in *Network) DeepCopy() *Network { + if in == nil { + return nil + } + out := new(Network) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Settings) DeepCopyInto(out *Settings) { *out = *in @@ -92,9 +122,9 @@ func (in *Workload) DeepCopyInto(out *Workload) { *out = new(deployment.Deployment) (*in).DeepCopyInto(*out) } - if in.Backend != nil { - in, out := &in.Backend, &out.Backend - *out = new(Backend) + if in.Network != nil { + in, out := &in.Network, &out.Network + *out = new(Network) (*in).DeepCopyInto(*out) } } diff --git a/application/instance.go b/application/instance.go index 05238ae..2f78d38 100644 --- a/application/instance.go +++ b/application/instance.go @@ -38,7 +38,6 @@ func Init(i Instance) { for _, o := range c.GetObjects() { meta.SetObjectMeta(c, o) - // fmt.Println(o.GetName()) } c.SetDefaults() diff --git a/application/settings/config.go b/application/settings/config.go index 72b9d81..306c128 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -21,21 +21,29 @@ import ( "k8s.libre.sh/utils" ) +// ConfigSpec defines a list of parameters and some sources from which those parameters can be fetched +// It can be used in the conta // +kubebuilder:object:generate=true type ConfigSpec struct { - SecretRefs []string `json:"secretRefs,omitempty"` - ConfigRefs []string `json:"configRefs,omitempty"` + // SecretRefs is a list of secrets in the name namespace + SecretRefs []string `json:"secretRefs,omitempty"` + // ConfigRefs is a list of configmaps in the name namespace + ConfigRefs []string `json:"configRefs,omitempty"` + // Parameters is a list of parameters *parameters.Parameters `json:"parameters,omitempty"` } +// SetParameters sets the parameters func (c *ConfigSpec) SetParameters(parameters *parameters.Parameters) { c.Parameters = parameters } +// GetParameters return the parameters func (c *ConfigSpec) GetParameters() *parameters.Parameters { if c.Parameters == nil { c.Parameters = new(parameters.Parameters) } return c.Parameters } + func (c *ConfigSpec) GetConfigRefs() []string { return c.ConfigRefs } func (c *ConfigSpec) SetConfigRefs(refs []string) { c.ConfigRefs = refs } @@ -44,6 +52,7 @@ func (c *ConfigSpec) GetSecretRefs() []string { return c.SecretRefs } func (c *ConfigSpec) SetSecretRefs(refs []string) { c.SecretRefs = refs } +// GetEnvFrom returns a list of sources to populate environment variables in the container. func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { envFroms := []corev1.EnvFromSource{} envFrom := corev1.EnvFromSource{} diff --git a/application/settings/parameters/parameter.go b/application/settings/parameters/parameter.go index fbc4729..c33e2a1 100644 --- a/application/settings/parameters/parameter.go +++ b/application/settings/parameters/parameter.go @@ -16,16 +16,27 @@ limitations under the License. package parameters const ( - GenerateRand Generate = "rand" - GenerateRand12 Generate = "rand12" - GenerateRand24 Generate = "rand24" + // Random value + GenerateRand Generate = "rand" + // Random value of size 12 + GenerateRand12 Generate = "rand12" + // Random value of size 24 + GenerateRand24 Generate = "rand24" + // Value is generated from a template + // Value container the template and will be replaced GenerateTemplate Generate = "template" ) const ( + // Parameter is mounted as key/value in the container envVar specs MountLiteral MountType = "literal" - MountFrom MountType = "from" - MountFile MountType = "file" + // Parameter is mounted as as EnvVarSource in the container envVar specs + // no data is transformed + MountFrom MountType = "from" + MountFile MountType = "file" + // Parameter is mounted as EnvFromSource in the container specs + // Data can be retrieved from the the crds or external resources specified in the envFrom + // and transformed in a new secret or configmap MountEnvFile MountType = "envFile" ) @@ -33,6 +44,7 @@ const ( ConfigParameter ParameterType = "configmap" SecretParameter ParameterType = "secret" ObjectFieldParameter ParameterType = "field" + TemplateValue ParameterType = "templateValue" ) type MountType string @@ -44,28 +56,34 @@ type Parameters []*Parameter // +kubebuilder:object:generate=true type Parameter struct { - // Key that will be mounted as environment variable + // Key of the parameter, can be mounted as as an environment variable, used in template + // or as in the data fied of configmap/secret Key string `json:"key,omitempty"` // Value of the paramater, should not contain secret values + // It can be a template, ParameterType should be template Value string `json:"value,omitempty"` - // ValueFrom specifies where to get the value from for the parameter + // ValueFrom when specified indicates the source of the parameter. + // Cannot be used if value is not empty. ValueFrom `json:",inline"` - // MountFrom specifies where the parameter will be mounted as file + // MountPath specifies where the parameter will be mounted as a file MountPath MountPath `json:"mountFrom,omitempty"` - // Generate is specified if a secret or configmap data needs to be randomly generated + // Generate if specified defines how the parameter value will be generated Generate Generate `json:"generate,omitempty"` - // Type specifies if its a ConfigMap or Secret - Type ParameterType `json:"type,omitempty"` - MountType MountType `json:"mountType,omitempty"` + // Type specifies specifies the parameter type + Type ParameterType `json:"type,omitempty"` + // MountType defined how the parameter will be mounted in the pod + // Defaults to EnvFile + MountType MountType `json:"mountType,omitempty"` } type ValueFrom struct { - // Key to select from in ConfigMap or Secret + // Key to select from the source FromKey string `json:"fromKey,omitempty"` - // Ref is a reference to a local object, set ParameterType to define the object + // Name of the referent. Ref string `json:"ref,omitempty"` - // Type specifies if its a ConfigMap or Secret - SourceType ParameterType `json:"type,omitempty"` + // Type of the source othe parameter + // Defaults to the parameter type if not specified + Type ParameterType `json:"type,omitempty"` } type MountPath struct { diff --git a/application/settings/parameters/parameter_helper.go b/application/settings/parameters/parameter_helper.go index d92b413..9f58950 100644 --- a/application/settings/parameters/parameter_helper.go +++ b/application/settings/parameters/parameter_helper.go @@ -21,10 +21,10 @@ import ( corev1 "k8s.io/api/core/v1" ) +// GetEnvVar gets an environment variables to set in the container. func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { switch p.MountType { - case MountLiteral: if len(p.Value) > 0 && len(p.Key) > 0 { envVar := corev1.EnvVar{ diff --git a/application/settings/parameters/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go index 7a9e9fd..9ef19e9 100644 --- a/application/settings/parameters/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -31,6 +31,7 @@ func (p *Parameters) InitValues() { p.InitTemplateValues(KeyPairValues(p)) } +// InitRandValues initialies the parameters random values func (p *Parameters) InitRandValues() { for _, param := range *p { @@ -55,6 +56,9 @@ func (p *Parameters) InitRandValues() { } } +// InitTemplateValues initialies the parameters values from a template and a key pair value set +// The template shoud be in the parameter value when GenerateTemplate is specified and the values +// will be replaced from the result of the template processing. func (p *Parameters) InitTemplateValues(values map[string]string) error { for _, param := range *p { @@ -78,6 +82,9 @@ func (p *Parameters) InitTemplateValues(values map[string]string) error { return nil } +// GetData get the data for the secret or configmap as a key:values +// This function only returns data which should be either in a secret or a configmap +// It implements the configmap and secret interfaces func (p *Parameters) GetData() map[string]string { data := make(map[string]string) @@ -92,7 +99,8 @@ func (p *Parameters) GetData() map[string]string { return data } -func (p *Parameters) GetConfig() []corev1.EnvVar { +// GetEnvVar gets a list of environment variables to set in the container. +func (p *Parameters) GetEnvVar() []corev1.EnvVar { envVars := []corev1.EnvVar{} envVar := corev1.EnvVar{} @@ -115,7 +123,14 @@ func (p *Parameters) GetConfig() []corev1.EnvVar { return nil } -func GetAndMergeParameters(params Parameters, paramsByKey map[string]*Parameter, c client.Client, obj interfaces.Object) error { +func GetAndMergeParameters( + params Parameters, + paramsByKey map[string]*Parameter, + c client.Client, + obj interfaces.Object) error { + + var pType ParameterType + data := map[string]string{} objectKey, _ := client.ObjectKeyFromObject(obj) @@ -125,14 +140,16 @@ func GetAndMergeParameters(params Parameters, paramsByKey map[string]*Parameter, return err } - data := map[string]string{} + // switch obj.GetObjectKind().GroupVersionKind().Kind if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { + pType = SecretParameter for k, v := range obj.(*corev1.Secret).Data { data[k] = string(v) } } if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { + pType = ConfigParameter for k, v := range obj.(*corev1.ConfigMap).Data { data[k] = v } @@ -144,13 +161,16 @@ func GetAndMergeParameters(params Parameters, paramsByKey map[string]*Parameter, } } else { for kk, vv := range data { + // TODO TO FIX if paramsByKey[kk] == nil { paramsByKey[kk] = new(Parameter) + } paramsByKey[kk].Value = vv paramsByKey[kk].Key = kk - // TODO This would be checked if we want to recreate the data or juste mount the whole secret + // TODO This would be checked if we want to recreate the data or just mount the whole secret paramsByKey[kk].MountType = MountEnvFile + paramsByKey[kk].Type = pType } } diff --git a/application/settings/parameters/parameters_test.go b/application/settings/parameters/parameters_test.go index 2511225..adcbb4b 100644 --- a/application/settings/parameters/parameters_test.go +++ b/application/settings/parameters/parameters_test.go @@ -272,7 +272,7 @@ var _ = Describe("Parameters", func() { } parameters.InitValues() - res := parameters.GetConfig() + res := parameters.GetEnvVar() Expect(res).To(Equal(expectedObj)) // Expect(err).NotTo(HaveOccurred()) diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index ca74d0a..9f30e72 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -56,16 +56,17 @@ func Marshal(i interface{}) (Parameters, error) { return parameters, nil } +// Sort parameters by keys, it takes the fromKey if it exists func ParametersByKey(p *Parameters) map[string]*Parameter { paramsByKey := map[string]*Parameter{} - for _, p := range *p { - paramsByKey[p.Key] = p + for _, param := range *p { + paramsByKey[param.Key] = param } - return paramsByKey } +// Transform parameters to key:value func KeyPairValues(p *Parameters) map[string]string { data := make(map[string]string) diff --git a/objects/container/mutate.go b/objects/container/mutate.go index af36fe0..5656cbd 100644 --- a/objects/container/mutate.go +++ b/objects/container/mutate.go @@ -23,7 +23,7 @@ type Mutate interface { // Parameters // GetVolumeMount() []corev1.VolumeMount GetEnvFrom() []corev1.EnvFromSource - GetConfig() []corev1.EnvVar + GetEnvVar() []corev1.EnvVar // Runtime GetContainerName() string GetContainerImage() string @@ -44,7 +44,7 @@ func MutateContainer(r Mutate, obj *corev1.Container) error { obj.Args = r.GetContainerArgs() obj.EnvFrom = r.GetEnvFrom() - obj.Env = r.GetConfig() + obj.Env = r.GetEnvVar() // obj.VolumeMounts = r.GetVolumeMount() diff --git a/objects/container/object.go b/objects/container/object.go index 3fa44da..23fb0c8 100644 --- a/objects/container/object.go +++ b/objects/container/object.go @@ -28,19 +28,64 @@ type Container struct { // +kubebuilder:object:generate=true type TemplateSpec struct { - Name string `json:"name,omitempty"` - Args []string `json:"args,omitempty"` - Image string `json:"image,omitempty"` - ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` - ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` - Ports []corev1.ContainerPort `json:"ports,omitempty"` - Probes `json:"inline,omitempty"` + // Name of the container specified as a DNS_LABEL. + // Each container in a pod must have a unique name (DNS_LABEL). + // Cannot be updated. + Name string `json:"name,omitempty"` + // Docker image name. + // More info: https://kubernetes.io/docs/concepts/containers/images + // This field is optional to allow higher level config management to default or override + // container images in workload controllers like Deployments and StatefulSets. + // +optional + Image string `json:"image,omitempty"` + // Arguments to the entrypoint. + // The docker image's CMD is used if this is not provided. + // Variable references $(VAR_NAME) are expanded using the container's environment. If a variable + // cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax + // can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, + // regardless of whether the variable exists or not. + // Cannot be updated. + // More info: https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell + // +optional + Args []string `json:"args,omitempty"` + // List of ports to expose from the container. Exposing a port here gives + // the system additional information about the network connections a + // container uses, but is primarily informational. Not specifying a port here + // DOES NOT prevent that port from being exposed. Any port which is + // listening on the default "0.0.0.0" address inside a container will be + // accessible from the network. + // Cannot be updated. + // +optional + // +patchMergeKey=containerPort + // +patchStrategy=merge + // +listType=map + // +listMapKey=containerPort + // +listMapKey=protocol + Ports []corev1.ContainerPort `json:"ports,omitempty"` + // Image pull policy. + // One of Always, Never, IfNotPresent. + // Defaults to Always if :latest tag is specified, or IfNotPresent otherwise. + // Cannot be updated. + // More info: https://kubernetes.io/docs/concepts/containers/images#updating-images + // +optional + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + Probes `json:"inline,omitempty"` } // +kubebuilder:object:generate=true type Probes struct { + // Periodic probe of container liveness. + // Container will be restarted if the probe fails. + // Cannot be updated. + // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes + // +optional ReadinessProbe *corev1.Probe `json:"readinessProbe,omitempty" protobuf:"bytes,11,opt,name=readinessProbe"` - LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,10,opt,name=livenessProbe"` + // Periodic probe of container liveness. + // Container will be restarted if the probe fails. + // Cannot be updated. + // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes + // +optional + LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,10,opt,name=livenessProbe"` } func (r *TemplateSpec) GetContainerImage() string { return r.Image } diff --git a/objects/container/zz_generated.deepcopy.go b/objects/container/zz_generated.deepcopy.go index edd432f..775593f 100644 --- a/objects/container/zz_generated.deepcopy.go +++ b/objects/container/zz_generated.deepcopy.go @@ -80,11 +80,6 @@ func (in *TemplateSpec) DeepCopyInto(out *TemplateSpec) { *out = make([]string, len(*in)) copy(*out, *in) } - if in.ImagePullSecrets != nil { - in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]v1.LocalObjectReference, len(*in)) - copy(*out, *in) - } if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]v1.ContainerPort, len(*in)) diff --git a/objects/pod/object.go b/objects/pod/object.go index 60b2dfb..68d4fd1 100644 --- a/objects/pod/object.go +++ b/objects/pod/object.go @@ -30,16 +30,61 @@ type Pod struct { // +kubebuilder:object:generate=true type PodSpec struct { - *meta.ObjectMeta `json:"meta,omitempty"` - Resources corev1.ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,8,opt,name=resources"` - SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,14,opt,name=securityContext"` - Affinity *corev1.Affinity `json:"affinity,omitempty"` - RestartPolicy corev1.RestartPolicy `json:"restartPolicy,omitempty"` - Tolerations []corev1.Toleration `json:"tolerations,omitempty"` - NodeSelector map[string]string `json:"nodeSelector,omitempty"` + *meta.ObjectMeta `json:"meta,omitempty"` + Resources corev1.ResourceRequirements `json:"resources,omitempty" protobuf:"bytes,8,opt,name=resources"` + // SecurityContext holds pod-level security attributes and common container settings. + // Optional: Defaults to empty. See type description for default values of each field. + // +optional + SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,14,opt,name=securityContext"` + // If specified, the pod's scheduling constraints + // +optional + Affinity *corev1.Affinity `json:"affinity,omitempty"` + // Restart policy for all containers within the pod. + // One of Always, OnFailure, Never. + // Default to Always. + // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy + // +optional + RestartPolicy corev1.RestartPolicy `json:"restartPolicy,omitempty"` + // If specified, the pod's tolerations. + // +optional + Tolerations []corev1.Toleration `json:"tolerations,omitempty"` + // NodeSelector is a selector which must be true for the pod to fit on a node. + // Selector which must match a node's labels for the pod to be scheduled on that node. + // More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ + // +optional + NodeSelector map[string]string `json:"nodeSelector,omitempty"` container.Container `json:",inline"` - ExtraContainers []container.Container `json:"extraContainers,omitempty"` - InitContainers []container.Container `json:"initContainers,omitempty"` + // List of containers belonging to the pod. + // Containers cannot currently be added or removed. + // There must be at least one container in a Pod. + // Cannot be updated. + // +patchMergeKey=name + // +patchStrategy=merge + ExtraContainers []container.Container `json:"extraContainers,omitempty"` + // List of initialization containers belonging to the pod. + // Init containers are executed in order prior to containers being started. If any + // init container fails, the pod is considered to have failed and is handled according + // to its restartPolicy. The name for an init container or normal container must be + // unique among all containers. + // Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. + // The resourceRequirements of an init container are taken into account during scheduling + // by finding the highest request/limit for each resource type, and then using the max of + // of that value or the sum of the normal containers. Limits are applied to init containers + // in a similar fashion. + // Init containers cannot currently be added or removed. + // Cannot be updated. + // More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ + // +patchMergeKey=name + // +patchStrategy=merge + InitContainers []container.Container `json:"initContainers,omitempty"` + // ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec. + // If specified, these secrets will be passed to individual puller implementations for them to use. For example, + // in the case of docker, only DockerConfig type secrets are honored. + // More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod + // +optional + // +patchMergeKey=name + // +patchStrategy=merge + ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } func (r *PodSpec) GetPodAffinity() *corev1.Affinity { return r.Affinity } diff --git a/objects/pod/zz_generated.deepcopy.go b/objects/pod/zz_generated.deepcopy.go index 1b30395..a33772b 100644 --- a/objects/pod/zz_generated.deepcopy.go +++ b/objects/pod/zz_generated.deepcopy.go @@ -93,6 +93,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]v1.LocalObjectReference, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodSpec. diff --git a/objects/service/object.go b/objects/service/object.go index ae77510..9079d6e 100644 --- a/objects/service/object.go +++ b/objects/service/object.go @@ -22,8 +22,30 @@ type Service struct { // +kubebuilder:object:generate=true type ServiceSpec struct { - Ports []Port `json:"ports,omitempty"` - Type corev1.ServiceType `json:"type,omitempty"` + // The list of ports that are exposed by this service. + // More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies + // +patchMergeKey=port + // +patchStrategy=merge + // +listType=map + // +listMapKey=port + // +listMapKey=protocol + Ports []Port `json:"ports,omitempty"` + // type determines how the Service is exposed. Defaults to ClusterIP. Valid + // options are ExternalName, ClusterIP, NodePort, and LoadBalancer. + // "ExternalName" maps to the specified externalName. + // "ClusterIP" allocates a cluster-internal IP address for load-balancing to + // endpoints. Endpoints are determined by the selector or if that is not + // specified, by manual construction of an Endpoints object. If clusterIP is + // "None", no virtual IP is allocated and the endpoints are published as a + // set of endpoints rather than a stable IP. + // "NodePort" builds on ClusterIP and allocates a port on every node which + // routes to the clusterIP. + // "LoadBalancer" builds on NodePort and creates an + // external load-balancer (if supported in the current cloud) which routes + // to the clusterIP. + // More info: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + // +optional + Type corev1.ServiceType `json:"type,omitempty"` } type Port struct { -- GitLab From f43d9c461691426d5e881687d74125dfcfb5c3a2 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 03:49:26 +0200 Subject: [PATCH 04/18] add some doc --- application/component.go | 15 +++++ application/components/network.go | 4 +- application/components/settings.go | 4 +- application/components/workload.go | 4 +- application/instance.go | 15 +++++ application/settings.go | 4 +- application/settings/config.go | 27 ++++++-- application/settings/interface.go | 4 +- application/settings/parameters/parameter.go | 4 +- .../settings/parameters/parameter_helper.go | 4 +- .../settings/parameters/parameters_helpers.go | 4 +- application/settings/parameters/utils.go | 4 +- application/settings/utils.go | 6 +- interfaces/interfaces.go | 10 ++- meta/instance.go | 29 ++++----- meta/meta.go | 18 ++--- meta/object.go | 65 +++++++++++++++++-- objects/configmap/mutate.go | 4 +- objects/configmap/object.go | 4 +- objects/container/mutate.go | 4 +- objects/container/object.go | 12 +++- objects/deployment/deployment.go | 27 +++++--- objects/deployment/mutate.go | 4 +- objects/ingress/mutate.go | 15 +++++ objects/ingress/object.go | 15 +++++ objects/object.go | 13 +++- objects/pod/mutate.go | 4 +- objects/pod/object.go | 14 +++- objects/secret/mutate.go | 4 +- objects/secret/object.go | 4 +- objects/service/mutate.go | 15 +++++ objects/service/object.go | 15 +++++ utils/utils.go | 15 +++++ 33 files changed, 295 insertions(+), 95 deletions(-) diff --git a/application/component.go b/application/component.go index 4482647..244ee4b 100644 --- a/application/component.go +++ b/application/component.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 application import ( diff --git a/application/components/network.go b/application/components/network.go index 50f4521..8f81269 100644 --- a/application/components/network.go +++ b/application/components/network.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/components/settings.go b/application/components/settings.go index 85c715d..675f802 100644 --- a/application/components/settings.go +++ b/application/components/settings.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/components/workload.go b/application/components/workload.go index d981964..abdb0b0 100644 --- a/application/components/workload.go +++ b/application/components/workload.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/instance.go b/application/instance.go index 2f78d38..6fa8aa2 100644 --- a/application/instance.go +++ b/application/instance.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 application import ( diff --git a/application/settings.go b/application/settings.go index 2dfc36c..a8bdeb7 100644 --- a/application/settings.go +++ b/application/settings.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/config.go b/application/settings/config.go index 306c128..14068cd 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,23 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package settings provides some api types and interfaces to manage settings in kubernetes +// +// Settings can be provided in: +// - The parent CRD with the parameter type +// - ConfigMaps and Secrets +// +// Settings can be passed to a container: +// - As EnvVar in the container spec (name & value) +// - As EnvVarFrom in the container spec with a fromKey and secret/configMap source +// - As EnvVarFrom object +// - As EnvFrom mounting all the data from a secret/configmap as env var +// - As a file configmap/secret +// +// Settings value: +// - can be randomly generate +// - provided in the crd +// - generate by template package settings import ( @@ -21,8 +38,8 @@ import ( "k8s.libre.sh/utils" ) -// ConfigSpec defines a list of parameters and some sources from which those parameters can be fetched -// It can be used in the conta +// ConfigSpec defines a list of parameters and references to resources from which those parameters can be fetched +// Only secrets and configmaps in the same namespace are supported as references // +kubebuilder:object:generate=true type ConfigSpec struct { // SecretRefs is a list of secrets in the name namespace @@ -52,7 +69,7 @@ func (c *ConfigSpec) GetSecretRefs() []string { return c.SecretRefs } func (c *ConfigSpec) SetSecretRefs(refs []string) { c.SecretRefs = refs } -// GetEnvFrom returns a list of sources to populate environment variables in the container. +// GetEnvFrom returns a list of EnvFromSource to populate environment variables in the container. func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { envFroms := []corev1.EnvFromSource{} envFrom := corev1.EnvFromSource{} diff --git a/application/settings/interface.go b/application/settings/interface.go index e786c52..09bd108 100644 --- a/application/settings/interface.go +++ b/application/settings/interface.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/parameters/parameter.go b/application/settings/parameters/parameter.go index c33e2a1..2d20871 100644 --- a/application/settings/parameters/parameter.go +++ b/application/settings/parameters/parameter.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/parameters/parameter_helper.go b/application/settings/parameters/parameter_helper.go index 9f58950..dbdd998 100644 --- a/application/settings/parameters/parameter_helper.go +++ b/application/settings/parameters/parameter_helper.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/parameters/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go index 9ef19e9..79e0d2d 100644 --- a/application/settings/parameters/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index 9f30e72..cad40a6 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/application/settings/utils.go b/application/settings/utils.go index a4ce037..444d0c9 100644 --- a/application/settings/utils.go +++ b/application/settings/utils.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -22,7 +22,7 @@ func OrderByResourceRef(s *ConfigSpec) (secrets, configs map[string]parameters.P configs = make(map[string]parameters.Parameters) // We order the parameters by secret and configmap sources - // First we get the sources provided as resources that should be mounted untouched + // First we get the sources provided that should be mounted untouched for _, ref := range s.SecretRefs { secrets[ref] = parameters.Parameters{} } diff --git a/interfaces/interfaces.go b/interfaces/interfaces.go index 70993df..9d1dad7 100644 --- a/interfaces/interfaces.go +++ b/interfaces/interfaces.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -25,18 +25,16 @@ import ( // Reconcile is the interface for Reconcile object structs . This // interface can be used to pass around Reconcile structs commonly -// used in Operators. +// used in Kubebuilder. // // Note however that by default Reconcile structs generated using -// Operator SDK do not implement this interface. Add following +// Kubebuilder do not implement this interface. Add following // functions to implement this interface. // // func (r *ReconcileObject) GetClient() client.Client { return r.client } // func (r *ReconcileObject) GetScheme() *runtime.Scheme { return r.scheme } // func (r *ReconcileObject) GetScheme() *runtime.Recorder { return r.recorder } // -// The Reconcile object structs must implement this interface to use -// Operatorlib functions. type Reconcile interface { // Getter function for reconcile client GetClient() client.Client diff --git a/meta/instance.go b/meta/instance.go index 594c05b..f4e61a5 100644 --- a/meta/instance.go +++ b/meta/instance.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -21,37 +21,31 @@ import ( "k8s.io/apimachinery/pkg/labels" ) +// TODO remove meta in interface, not needed +// Instance interface can work with the commons app.kubernetes.io labels - https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/#labels type Instance interface { Meta + // The name of the application - app.kubernetes.io/name GetApplication() string SetApplication(string) + // A unique name identifying the instance of an application - app.kubernetes.io/instance GetInstance() string SetInstance(string) + // The current version of the application (e.g., a semantic version, revision hash, etc.) - app.kubernetes.io/version GetVersion() string SetVersion(string) + // The component within the architecture - app.kubernetes.io/component GetComponent() string SetComponent(string) + // The name of a higher level application this one is part of - app.kubernetes.io/part-of GetPartOf() string SetPartOf(string) + // The tool being used to manage the operation of an application - app.kubernetes.io/managed-by GetManagedBy() string SetManagedBy(string) } -/* type Application interface { - GetApplication() string - SetApplication(string) - GetInstance() string - SetInstance(string) - GetVersion() string - SetVersion(string) - GetComponent() string - SetComponent(string) - GetPartOf() string - SetPartOf(string) - GetManagedBy() string - SetManagedBy(string) -} */ - +// Instance labels returns the app.kubernetes.io labels func InstanceLabels(m Instance) map[string]string { labels := labels.Set{ "app.kubernetes.io/name": m.GetApplication(), @@ -64,6 +58,7 @@ func InstanceLabels(m Instance) map[string]string { return labels } +// TODO user Object interface and rename Merge ? func SetObjectMeta(src Instance, dest Instance) { dest.SetLabels(labels.Merge(dest.GetLabels(), InstanceLabels(src))) diff --git a/meta/meta.go b/meta/meta.go index c487da9..1aaad82 100644 --- a/meta/meta.go +++ b/meta/meta.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,10 @@ import ( interfaces "k8s.libre.sh/interfaces" ) +// Meta interface is a stripped down version of https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#Object with +// only user definied specs. +// +// To mutates an object a type must implements this interface type Meta interface { GetLabels() map[string]string SetLabels(labels map[string]string) @@ -31,6 +35,7 @@ type Meta interface { SetNamespace(string) } +// MutateMeta mutates an Object meta func MutateMeta(o Meta, obj interfaces.Object) error { obj.SetLabels(o.GetLabels()) @@ -38,14 +43,5 @@ func MutateMeta(o Meta, obj interfaces.Object) error { obj.SetAnnotations(labels.Merge(obj.GetAnnotations(), o.GetAnnotations())) } - // if len(obj.GetName()) == 0 { - // obj.SetName(o.GetName()) - - // } - - // if len(obj.GetNamespace()) == 0 { - // obj.SetNamespace(o.GetNamespace()) - // } - return nil } diff --git a/meta/object.go b/meta/object.go index e16612d..749aa65 100644 --- a/meta/object.go +++ b/meta/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -15,14 +15,50 @@ limitations under the License. package meta +// ObjectMeta meta is a stripped down version of the ObjectMeta type https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta +// with only user defined specs +// +// This type can be used in an application CRD +// ObjectMeta implements the Meta interface and can be used to mutates an object +// // +kubebuilder:object:generate=true type ObjectMeta struct { - Name string `json:"name,omitempty"` - Namespace string `json:"namespace,omitempty"` - Labels map[string]string `json:"labels,omitempty"` + // Name must be unique within a namespace. Is required when creating resources, although + // some resources may allow a client to request the generation of an appropriate name + // automatically. Name is primarily intended for creation idempotence and configuration + // definition. + // Cannot be updated. + // More info: http://kubernetes.io/docs/user-guide/identifiers#names + // +optional + Name string `json:"name,omitempty"` + + // Namespace defines the space within each name must be unique. An empty namespace is + // equivalent to the "default" namespace, but "default" is the canonical representation. + // Not all objects are required to be scoped to a namespace - the value of this field for + // those objects will be empty. + // + // Must be a DNS_LABEL. + // Cannot be updated. + // More info: http://kubernetes.io/docs/user-guide/namespaces + // +optional + Namespace string `json:"namespace,omitempty"` + + // Map of string keys and values that can be used to organize and categorize + // (scope and select) objects. May match selectors of replication controllers + // and services. + // More info: http://kubernetes.io/docs/user-guide/labels + // +optional + Labels map[string]string `json:"labels,omitempty"` + + // Annotations is an unstructured key value map stored with a resource that may be + // set by external tools to store and retrieve arbitrary metadata. They are not + // queryable and should be preserved when modifying objects. + // More info: http://kubernetes.io/docs/user-guide/annotations + // +optional Annotations map[string]string `json:"annotations,omitempty"` } +// SetLabels sets the ObjectMeta labels func (c *ObjectMeta) SetLabels(labels map[string]string) { if len(c.Labels) == 0 { c.Labels = make(map[string]string) @@ -36,6 +72,7 @@ func (c *ObjectMeta) SetLabels(labels map[string]string) { } } +// SetAnnotations sets the ObjectMeta annotations func (c *ObjectMeta) SetAnnotations(annotations map[string]string) { if len(c.Annotations) == 0 { c.Annotations = make(map[string]string) @@ -49,38 +86,56 @@ func (c *ObjectMeta) SetAnnotations(annotations map[string]string) { } } +// GetLabels returns the ObjectMeta labels func (c *ObjectMeta) GetLabels() map[string]string { return c.Labels } +// GetAnnotations returns the Annotations labels func (c *ObjectMeta) GetAnnotations() map[string]string { return c.Annotations } +// GetName returns the ObjectMeta name func (o *ObjectMeta) GetName() string { return o.Name } +// SetName sets the ObjectMeta name func (o *ObjectMeta) SetName(name string) { o.Name = name } +// GetNamespace returns the ObjectMeta namespace func (o *ObjectMeta) GetNamespace() string { return o.Namespace } +// SetNamespace sets the ObjectMeta namespace func (o *ObjectMeta) SetNamespace(namespace string) { o.Namespace = namespace } +// GetApplication returns the ObjectMeta application name from the app.kubernetes.io/name label func (c *ObjectMeta) GetApplication() string { return c.Labels["app.kubernetes.io/name"] } +// SetApplication sets the ObjectMeta application name from the app.kubernetes.io/name label func (c *ObjectMeta) SetApplication(s string) { c.Labels["app.kubernetes.io/name"] = s } +// GetInstance returns the ObjectMeta application name from the app.kubernetes.io/instance label func (c *ObjectMeta) GetInstance() string { return c.Labels["app.kubernetes.io/instance"] } +// SetInstance sets the ObjectMeta application name from the app.kubernetes.io/instance label func (c *ObjectMeta) SetInstance(s string) { c.Labels["app.kubernetes.io/instance"] = s } +// GetVersion returns the ObjectMeta application name from the app.kubernetes.io/version label func (c *ObjectMeta) GetVersion() string { return c.Labels["app.kubernetes.io/version"] } +// SetVersion sets the ObjectMeta application name from the app.kubernetes.io/version label func (c *ObjectMeta) SetVersion(s string) { c.Labels["app.kubernetes.io/version"] = s } +// GetComponent returns the ObjectMeta application name from the app.kubernetes.io/component label func (c *ObjectMeta) GetComponent() string { return c.Labels["app.kubernetes.io/component"] } +// SetComponent sets the ObjectMeta application name from the app.kubernetes.io/component label func (c *ObjectMeta) SetComponent(s string) { c.Labels["app.kubernetes.io/component"] = s } +// GetPartOf returns the ObjectMeta application name from the app.kubernetes.io/part-of label func (c *ObjectMeta) GetPartOf() string { return c.Labels["app.kubernetes.io/part-of"] } +// SetPartOf sets the ObjectMeta application name from the app.kubernetes.io/part-of label func (c *ObjectMeta) SetPartOf(s string) { c.Labels["app.kubernetes.io/part-of"] = s } +// GetManagedBy returns the ObjectMeta application name from the app.kubernetes.io/managed-by label func (c *ObjectMeta) GetManagedBy() string { return c.Labels["app.kubernetes.io/managed-by"] } +// SetManagedBy sets the ObjectMeta application name from the app.kubernetes.io/managed-by label func (c *ObjectMeta) SetManagedBy(s string) { c.Labels["app.kubernetes.io/managed-by"] = s } diff --git a/objects/configmap/mutate.go b/objects/configmap/mutate.go index c6e35cb..3c326ea 100644 --- a/objects/configmap/mutate.go +++ b/objects/configmap/mutate.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/configmap/object.go b/objects/configmap/object.go index e0226cb..ef420e9 100644 --- a/objects/configmap/object.go +++ b/objects/configmap/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/container/mutate.go b/objects/container/mutate.go index 5656cbd..da16e14 100644 --- a/objects/container/mutate.go +++ b/objects/container/mutate.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/container/object.go b/objects/container/object.go index 23fb0c8..793f4be 100644 --- a/objects/container/object.go +++ b/objects/container/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,12 @@ import ( parameters "k8s.libre.sh/application/settings" ) +// Container is the specification of the desired behavior of the Container. +// It is a stripped down version of https://godoc.org/k8s.io/api/core/v1#Container +// with only user definied specs +// +// Parameters are used to define how settings are passed on to the container. +// // +kubebuilder:object:generate=true type Container struct { *TemplateSpec `json:",inline"` @@ -72,6 +78,8 @@ type TemplateSpec struct { Probes `json:"inline,omitempty"` } +// Periodic probe for container health +// // +kubebuilder:object:generate=true type Probes struct { // Periodic probe of container liveness. diff --git a/objects/deployment/deployment.go b/objects/deployment/deployment.go index bfc56cb..89c3b36 100644 --- a/objects/deployment/deployment.go +++ b/objects/deployment/deployment.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -24,15 +24,29 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// Deployment is the specification of the desired behavior of the Deployment. +// It is a stripped down version of https://godoc.org/k8s.io/api/apps/v1#Deployment +// with only user definied specs +// // +kubebuilder:object:generate=true type Deployment struct { *meta.ObjectMeta `json:"meta,omitempty"` *DeploymentSpec `json:",inline"` } +// DeploymentSpec is the specification of the desired behavior of the DeploymentSpec. +// It is a stripped down version of https://godoc.org/k8s.io/api/apps/v1#DeploymentSpec +// with only user definied specs +// // +kubebuilder:object:generate=true type DeploymentSpec struct { - Replicas *int32 `json:"replicas,omitempty"` + // Number of desired pods. This is a pointer to distinguish between explicit + // zero and not specified. Defaults to 1. + // +optional + Replicas *int32 `json:"replicas,omitempty"` + // The deployment strategy to use to replace existing pods with new ones. + // +optional + // +patchStrategy=retainKeys Strategy appsv1.DeploymentStrategy `json:"strategy,omitempty"` *pod.PodSpec `json:",inline"` } @@ -67,10 +81,3 @@ func (w *Deployment) Mutate(obj interfaces.Object) error { return nil } - -//func NewDeployment(spec *DeploymentSpec, p parameters.Parameters) *Deployment { -// return &Deployment{ -// Parameters: p, -// DeploymentSpec: spec, -// } -//} diff --git a/objects/deployment/mutate.go b/objects/deployment/mutate.go index f36491d..848371b 100644 --- a/objects/deployment/mutate.go +++ b/objects/deployment/mutate.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/ingress/mutate.go b/objects/ingress/mutate.go index 1f6f8a1..cce3d3e 100644 --- a/objects/ingress/mutate.go +++ b/objects/ingress/mutate.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 ingress import ( diff --git a/objects/ingress/object.go b/objects/ingress/object.go index bc312b0..e299707 100644 --- a/objects/ingress/object.go +++ b/objects/ingress/object.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 ingress import ( diff --git a/objects/object.go b/objects/object.go index d529f3e..d7e7093 100644 --- a/objects/object.go +++ b/objects/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Objects package contains core kubernetes resources definitions that can be included in an application CRD. +// The definitions are stripped down version with only specs that should be user-defined. +// +// Every objects definied in this package implements its own interface which can mutates its associated kubernetes resource. +// +// All those objects also implements the Object inteface from which we can create an object syncer - see https://github.com/presslabs/controller-util/syncer package objects import ( @@ -22,12 +28,15 @@ import ( "github.com/presslabs/controller-util/syncer" ) +// Object interface must be supported by all types that want to sync an object. +// The object interface provides a mutate function and a runtime.Object that can be used in controller-runtime CreateOrUpdate type Object interface { meta.Instance Mutate(obj interfaces.Object) error GetObject() interfaces.Object } +// NewObjectSyncer returns a syncer interface from https://github.com/presslabs/controller-util/syncer which can reconcile an object, create events and logs. func NewObjectSyncer(i Object, owner interfaces.Object, r interfaces.Reconcile) syncer.Interface { obj := i.GetObject() obj.SetName(i.GetName()) diff --git a/objects/pod/mutate.go b/objects/pod/mutate.go index 4bd43f8..20a8ff6 100644 --- a/objects/pod/mutate.go +++ b/objects/pod/mutate.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/pod/object.go b/objects/pod/object.go index 68d4fd1..44d8f1c 100644 --- a/objects/pod/object.go +++ b/objects/pod/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -28,6 +28,16 @@ type Pod struct { // Parameters parameters.Parameters `json:"parameters,omitempty"` } +// PodSpec is the specification of the desired behavior of the Pod. +// It is a stripped down version of https://godoc.org/k8s.io/api/core/v1#PodSpec +// with only user definied specs +// +// Here we consider that a pod has a main container that is embedded in the PodSpec definition +// +// Extra and init containers can also be definied +// +// This is similar to the container / sidecar container pattern +// // +kubebuilder:object:generate=true type PodSpec struct { *meta.ObjectMeta `json:"meta,omitempty"` diff --git a/objects/secret/mutate.go b/objects/secret/mutate.go index 92803b7..51cc1b0 100644 --- a/objects/secret/mutate.go +++ b/objects/secret/mutate.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/secret/object.go b/objects/secret/object.go index 2b37e0d..e1bb609 100644 --- a/objects/secret/object.go +++ b/objects/secret/object.go @@ -1,10 +1,10 @@ /* -Licensed under the Apache License, Version 2.0 (the "License"); +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (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 + https://www.gnu.org/licenses/agpl-3.0.html Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/objects/service/mutate.go b/objects/service/mutate.go index 49d6d31..29f6ee6 100644 --- a/objects/service/mutate.go +++ b/objects/service/mutate.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 service import ( diff --git a/objects/service/object.go b/objects/service/object.go index 9079d6e..261d2c0 100644 --- a/objects/service/object.go +++ b/objects/service/object.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 service import ( diff --git a/utils/utils.go b/utils/utils.go index ce6433a..200ac95 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -1,3 +1,18 @@ +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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 utils func Unique(stringSlice []string) []string { -- GitLab From 6d1509e61da7130a98de5e283602991c1f14483e Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 04:01:18 +0200 Subject: [PATCH 05/18] reorganize settings --- application/components/workload.go | 4 +- .../components/zz_generated.deepcopy.go | 34 ----------- application/instance.go | 5 +- .../settings.go => settings/component.go} | 25 ++++---- application/{ => settings}/settings.go | 12 ++-- application/settings/zz_generated.deepcopy.go | 58 +++++++++++++++++++ 6 files changed, 79 insertions(+), 59 deletions(-) rename application/{components/settings.go => settings/component.go} (85%) rename application/{ => settings}/settings.go (90%) create mode 100644 application/settings/zz_generated.deepcopy.go diff --git a/application/components/workload.go b/application/components/workload.go index abdb0b0..125a634 100644 --- a/application/components/workload.go +++ b/application/components/workload.go @@ -66,8 +66,8 @@ func (w *Workload) GetObjects() map[int]objects.Object { return objects } -func (w *Workload) SetDependencies(s *Settings) { w.ConfigSpec = s.ConfigSpec } -func (w *Workload) GetDependencies() settings.Config { return w.ConfigSpec } +func (w *Workload) SetDependencies(s *settings.Component) { w.ConfigSpec = s.ConfigSpec } +func (w *Workload) GetDependencies() settings.Config { return w.ConfigSpec } func (w *Workload) SetDefaults() { diff --git a/application/components/zz_generated.deepcopy.go b/application/components/zz_generated.deepcopy.go index c499360..eff2177 100644 --- a/application/components/zz_generated.deepcopy.go +++ b/application/components/zz_generated.deepcopy.go @@ -75,40 +75,6 @@ func (in *Network) DeepCopy() *Network { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Settings) DeepCopyInto(out *Settings) { - *out = *in - if in.CommonMeta != nil { - in, out := &in.CommonMeta, &out.CommonMeta - *out = new(meta.ObjectMeta) - (*in).DeepCopyInto(*out) - } - if in.SecretMeta != nil { - in, out := &in.SecretMeta, &out.SecretMeta - *out = new(meta.ObjectMeta) - (*in).DeepCopyInto(*out) - } - if in.ConfigMeta != nil { - in, out := &in.ConfigMeta, &out.ConfigMeta - *out = new(meta.ObjectMeta) - (*in).DeepCopyInto(*out) - } - if in.ConfigSpec != nil { - in, out := &in.ConfigSpec, &out.ConfigSpec - *out = (*in).DeepCopy() - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. -func (in *Settings) DeepCopy() *Settings { - if in == nil { - return nil - } - out := new(Settings) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Workload) DeepCopyInto(out *Workload) { *out = *in diff --git a/application/instance.go b/application/instance.go index 6fa8aa2..bf2e1eb 100644 --- a/application/instance.go +++ b/application/instance.go @@ -20,7 +20,6 @@ import ( "github.com/presslabs/controller-util/syncer" - "k8s.libre.sh/application/components" settings "k8s.libre.sh/application/settings" "k8s.libre.sh/interfaces" "k8s.libre.sh/meta" @@ -31,7 +30,7 @@ type Instance interface { meta.Instance GetComponents() map[int]Component GetOwner() interfaces.Object - GetSettings() Settings + GetSettings() settings.Settings SetDefaults() } @@ -69,7 +68,7 @@ func NewSyncers(app Instance, r interfaces.Reconcile, owner interfaces.Object) ( // TODO TO FIX SHOULD BE RUN IN INITIALIZED FUNCTION // INITIALISE VALUES FROM EXTERNAL RESOURCES, RANDOM & TEMPLATES // sett := app.GetSettings().GetConfig().(*components.Settings) - sett := app.GetSettings().(*components.Settings) + sett := app.GetSettings().(*settings.Component) err = sett.Init(r.GetClient()) diff --git a/application/components/settings.go b/application/settings/component.go similarity index 85% rename from application/components/settings.go rename to application/settings/component.go index 675f802..cea70c5 100644 --- a/application/components/settings.go +++ b/application/settings/component.go @@ -13,13 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package components +package settings import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" - "k8s.libre.sh/application/settings" "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/meta" "k8s.libre.sh/objects" @@ -28,31 +27,31 @@ import ( ) // +kubebuilder:object:generate=true -type Settings struct { +type Component struct { CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` DefaultType parameters.ParameterType `json:"defaultType,omitempty"` DefaultMountType parameters.MountType `json:"defaultMountType,omitempty"` // Template string `json:"template,omitempty"` - *settings.ConfigSpec `json:",inline"` + *ConfigSpec `json:",inline"` } -func (s *Settings) GetConfig() settings.Config { return s.ConfigSpec } +func (s *Component) GetConfig() Config { return s.ConfigSpec } -func (s *Settings) GetMeta() meta.Instance { return s.CommonMeta } +func (s *Component) GetMeta() meta.Instance { return s.CommonMeta } -func (s *Settings) GetSecretMeta() meta.Instance { return s.SecretMeta } +func (s *Component) GetSecretMeta() meta.Instance { return s.SecretMeta } -func (s *Settings) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } +func (s *Component) GetConfigMapMeta() meta.Instance { return s.ConfigMeta } -func (s *Settings) SetDefaults() { +func (s *Component) SetDefaults() { // TODO TO FIX DUPLICATE WITH INIT meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) } -func (s *Settings) GetObjects() map[int]objects.Object { +func (s *Component) GetObjects() map[int]objects.Object { cm := &configmap.ConfigMap{ ObjectMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), @@ -102,7 +101,7 @@ func (s *Settings) GetObjects() map[int]objects.Object { return objs } -func (s *Settings) Init(c client.Client) error { +func (s *Component) Init(c client.Client) error { // TODO TO FIX DUPLICATE WITH SETDEFAULTS meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) @@ -122,12 +121,12 @@ func (s *Settings) Init(c client.Client) error { // InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace // All parameters values are filled from those resources -func InitParametersValueFrom(s *Settings, c client.Client) error { +func InitParametersValueFrom(s *Component, c client.Client) error { params := parameters.Parameters{} paramsByKey := parameters.ParametersByKey(s.Parameters) - paramsBySecretSource, paramsByConfigMapSource := settings.OrderByResourceRef(s.ConfigSpec) + paramsBySecretSource, paramsByConfigMapSource := OrderByResourceRef(s.ConfigSpec) cm := &corev1.ConfigMap{} sec := &corev1.Secret{} diff --git a/application/settings.go b/application/settings/settings.go similarity index 90% rename from application/settings.go rename to application/settings/settings.go index a8bdeb7..4b2db5b 100644 --- a/application/settings.go +++ b/application/settings/settings.go @@ -13,11 +13,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -package application +package settings import ( - "k8s.libre.sh/application/components" - "k8s.libre.sh/application/settings" "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/meta" "k8s.libre.sh/objects" @@ -31,17 +29,17 @@ type Settings interface { GetMeta() meta.Instance GetSecretMeta() meta.Instance GetConfigMapMeta() meta.Instance - GetConfig() settings.Config + GetConfig() Config SetDefaults() Init(c client.Client) error } -func NewSettings(s Settings) *components.Settings { - return &components.Settings{ +func NewSettings(s Settings) *Component { + return &Component{ CommonMeta: s.GetMeta().(*meta.ObjectMeta), SecretMeta: s.GetSecretMeta().(*meta.ObjectMeta), ConfigMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), - ConfigSpec: &settings.ConfigSpec{ + ConfigSpec: &ConfigSpec{ ConfigRefs: s.GetConfig().GetConfigRefs(), SecretRefs: s.GetConfig().GetSecretRefs(), Parameters: s.GetConfig().GetParameters(), diff --git a/application/settings/zz_generated.deepcopy.go b/application/settings/zz_generated.deepcopy.go new file mode 100644 index 0000000..3847007 --- /dev/null +++ b/application/settings/zz_generated.deepcopy.go @@ -0,0 +1,58 @@ +// +build !ignore_autogenerated + +/* + +Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.gnu.org/licenses/agpl-3.0.html + +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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package settings + +import ( + "k8s.libre.sh/meta" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Component) DeepCopyInto(out *Component) { + *out = *in + if in.CommonMeta != nil { + in, out := &in.CommonMeta, &out.CommonMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) + } + if in.SecretMeta != nil { + in, out := &in.SecretMeta, &out.SecretMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) + } + if in.ConfigMeta != nil { + in, out := &in.ConfigMeta, &out.ConfigMeta + *out = new(meta.ObjectMeta) + (*in).DeepCopyInto(*out) + } + if in.ConfigSpec != nil { + in, out := &in.ConfigSpec, &out.ConfigSpec + *out = (*in).DeepCopy() + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Component. +func (in *Component) DeepCopy() *Component { + if in == nil { + return nil + } + out := new(Component) + in.DeepCopyInto(out) + return out +} -- GitLab From 33dc7fb2a09cb9afc68b7e38bb60c621278fde3a Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 16:46:59 +0200 Subject: [PATCH 06/18] fixes & refactor --- application/components/workload.go | 16 +- application/instance.go | 3 +- application/settings/component.go | 22 +- application/settings/config.go | 2 +- application/settings/interface.go | 5 +- application/settings/parameters/parameter.go | 9 +- .../settings/parameters/parameters_helpers.go | 57 ----- application/settings/parameters/utils.go | 62 ++++- application/settings/settings.go | 2 - go.mod | 3 +- go.sum | 230 ++++++++++++++++++ meta/instance.go | 2 +- objects/secret/mutate.go | 2 +- 13 files changed, 328 insertions(+), 87 deletions(-) diff --git a/application/components/workload.go b/application/components/workload.go index 125a634..ed54253 100644 --- a/application/components/workload.go +++ b/application/components/workload.go @@ -22,6 +22,8 @@ import ( deployment "k8s.libre.sh/objects/deployment" ) +const DefaultComponent string = "app" + // +kubebuilder:object:generate=true type Workload struct { *meta.ObjectMeta `json:"commonMeta,omitempty"` @@ -81,7 +83,7 @@ func (w *Workload) Init() { // TODO improve initialisation of objectMeta, labels... if w.ObjectMeta == nil { - w.ObjectMeta = new(meta.ObjectMeta) + w.ObjectMeta = &meta.ObjectMeta{} } if len(w.ObjectMeta.Labels) == 0 { @@ -89,14 +91,16 @@ func (w *Workload) Init() { } // TODO FIXME - w.ObjectMeta.SetComponent("app") + if len(w.ObjectMeta.GetComponent()) == 0 { + w.ObjectMeta.SetComponent(DefaultComponent) + } if w.Deployment.ObjectMeta == nil { - w.Deployment.ObjectMeta = new(meta.ObjectMeta) + w.Deployment.ObjectMeta = &meta.ObjectMeta{} } if w.ConfigSpec == nil { - w.ConfigSpec = new(settings.ConfigSpec) + w.ConfigSpec = &settings.ConfigSpec{} } if w.Backend == nil { @@ -104,10 +108,10 @@ func (w *Workload) Init() { } if w.ServiceMeta == nil { - w.ServiceMeta = new(meta.ObjectMeta) + w.ServiceMeta = &meta.ObjectMeta{} } if w.IngressMeta == nil { - w.IngressMeta = new(meta.ObjectMeta) + w.IngressMeta = &meta.ObjectMeta{} } } diff --git a/application/instance.go b/application/instance.go index bf2e1eb..e192550 100644 --- a/application/instance.go +++ b/application/instance.go @@ -31,6 +31,7 @@ type Instance interface { GetComponents() map[int]Component GetOwner() interfaces.Object GetSettings() settings.Settings + // GetSettings() map[int]settings.Settings SetDefaults() } @@ -83,7 +84,7 @@ func NewSyncers(app Instance, r interfaces.Reconcile, owner interfaces.Object) ( s := objects.NewObjectSyncer(obj, owner, r) if err := syncer.Sync(context.TODO(), s, r.GetRecorder()); err != nil { - // return nil, err + return syncers, err } } diff --git a/application/settings/component.go b/application/settings/component.go index cea70c5..650bacc 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -37,6 +37,14 @@ type Component struct { *ConfigSpec `json:",inline"` } +/* +type Component struct { + *meta.ObjectMeta `json:"commonMeta,omitempty"` + Secrets map[string]configmap.ConfigMap + Configs map[string]secret.Secret + // TemplateValues string +} +*/ func (s *Component) GetConfig() Config { return s.ConfigSpec } func (s *Component) GetMeta() meta.Instance { return s.CommonMeta } @@ -54,23 +62,16 @@ func (s *Component) SetDefaults() { func (s *Component) GetObjects() map[int]objects.Object { cm := &configmap.ConfigMap{ - ObjectMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), + ObjectMeta: s.ConfigMeta, } secret := &secret.Secret{ - ObjectMeta: s.GetSecretMeta().(*meta.ObjectMeta), + ObjectMeta: s.SecretMeta, } objs := make(map[int]objects.Object, 2) - // meta.SetObjectMeta(s.CommonMeta, cm.ObjectMeta) - // meta.SetObjectMeta(s.CommonMeta, secret.ObjectMeta) - - // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS - // params := s.GetConfig() - - for _, p := range *s.ConfigSpec.GetParameters() { - // TODO check not mountLiteral ?? + for _, p := range *s.ConfigSpec.Parameters { if p.MountType == parameters.MountEnvFile && p.Type == parameters.SecretParameter && len(p.Value) > 0 { @@ -89,7 +90,6 @@ func (s *Component) GetObjects() map[int]objects.Object { } if len(secret.Parameters) > 0 { - // secret.Parameters = secretParameters if objs[0] == nil { objs[0] = secret diff --git a/application/settings/config.go b/application/settings/config.go index 14068cd..0225fcd 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -56,7 +56,7 @@ func (c *ConfigSpec) SetParameters(parameters *parameters.Parameters) { c.Parame // GetParameters return the parameters func (c *ConfigSpec) GetParameters() *parameters.Parameters { if c.Parameters == nil { - c.Parameters = new(parameters.Parameters) + c.Parameters = ¶meters.Parameters{} } return c.Parameters } diff --git a/application/settings/interface.go b/application/settings/interface.go index 09bd108..f002d5c 100644 --- a/application/settings/interface.go +++ b/application/settings/interface.go @@ -15,7 +15,9 @@ limitations under the License. package settings -import "k8s.libre.sh/application/settings/parameters" +import ( + "k8s.libre.sh/application/settings/parameters" +) type Config interface { GetConfigRefs() []string @@ -26,6 +28,7 @@ type Config interface { SetSecretRefs([]string) InitRandValues() InitTemplateValues(map[string]string) error + // InitExternaValues(c client.Client) error } func MergeSettings(src, dest Config) Config { diff --git a/application/settings/parameters/parameter.go b/application/settings/parameters/parameter.go index 2d20871..211ed79 100644 --- a/application/settings/parameters/parameter.go +++ b/application/settings/parameters/parameter.go @@ -31,11 +31,12 @@ const ( // Parameter is mounted as key/value in the container envVar specs MountLiteral MountType = "literal" // Parameter is mounted as as EnvVarSource in the container envVar specs - // no data is transformed + // no data is transformed in a new resource MountFrom MountType = "from" + // Parameter is mouned as file in the container path MountFile MountType = "file" // Parameter is mounted as EnvFromSource in the container specs - // Data can be retrieved from the the crds or external resources specified in the envFrom + // Data can be retrieved from the the crds or external resources specified in the paramete envFrom // and transformed in a new secret or configmap MountEnvFile MountType = "envFile" ) @@ -81,9 +82,9 @@ type ValueFrom struct { FromKey string `json:"fromKey,omitempty"` // Name of the referent. Ref string `json:"ref,omitempty"` - // Type of the source othe parameter + // Type of the parameter's source // Defaults to the parameter type if not specified - Type ParameterType `json:"type,omitempty"` + RefType ParameterType `json:"refType,omitempty"` } type MountPath struct { diff --git a/application/settings/parameters/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go index 79e0d2d..5ea3c89 100644 --- a/application/settings/parameters/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -17,13 +17,10 @@ package parameters import ( "bytes" - "context" "text/template" "github.com/presslabs/controller-util/rand" corev1 "k8s.io/api/core/v1" - "k8s.libre.sh/interfaces" - "sigs.k8s.io/controller-runtime/pkg/client" ) func (p *Parameters) InitValues() { @@ -122,57 +119,3 @@ func (p *Parameters) GetEnvVar() []corev1.EnvVar { } return nil } - -func GetAndMergeParameters( - params Parameters, - paramsByKey map[string]*Parameter, - c client.Client, - obj interfaces.Object) error { - - var pType ParameterType - data := map[string]string{} - - objectKey, _ := client.ObjectKeyFromObject(obj) - - err := c.Get(context.Background(), objectKey, obj) - - if err != nil { - return err - } - - // switch obj.GetObjectKind().GroupVersionKind().Kind - - if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { - pType = SecretParameter - for k, v := range obj.(*corev1.Secret).Data { - data[k] = string(v) - } - } - if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { - pType = ConfigParameter - for k, v := range obj.(*corev1.ConfigMap).Data { - data[k] = v - } - } - - if len(params) > 0 { - for _, pp := range params { - paramsByKey[pp.Key].Value = string(data[pp.FromKey]) - } - } else { - for kk, vv := range data { - // TODO TO FIX - if paramsByKey[kk] == nil { - paramsByKey[kk] = new(Parameter) - - } - paramsByKey[kk].Value = vv - paramsByKey[kk].Key = kk - // TODO This would be checked if we want to recreate the data or just mount the whole secret - paramsByKey[kk].MountType = MountEnvFile - paramsByKey[kk].Type = pType - } - } - - return nil -} diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index cad40a6..c9409d3 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -16,7 +16,13 @@ limitations under the License. package parameters import ( + "context" "reflect" + + corev1 "k8s.io/api/core/v1" + + "k8s.libre.sh/interfaces" + "sigs.k8s.io/controller-runtime/pkg/client" ) func Marshal(i interface{}) (Parameters, error) { @@ -56,7 +62,7 @@ func Marshal(i interface{}) (Parameters, error) { return parameters, nil } -// Sort parameters by keys, it takes the fromKey if it exists +// Sort parameters by keys or fromKeys if it exist func ParametersByKey(p *Parameters) map[string]*Parameter { paramsByKey := map[string]*Parameter{} @@ -76,3 +82,57 @@ func KeyPairValues(p *Parameters) map[string]string { return data } + +func GetAndMergeParameters( + params Parameters, + paramsByKey map[string]*Parameter, + c client.Client, + obj interfaces.Object) error { + + var pType ParameterType + data := map[string]string{} + + objectKey, _ := client.ObjectKeyFromObject(obj) + + err := c.Get(context.Background(), objectKey, obj) + + if err != nil { + return err + } + + // switch obj.GetObjectKind().GroupVersionKind().Kind + + if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { + pType = SecretParameter + for k, v := range obj.(*corev1.Secret).Data { + data[k] = string(v) + } + } + if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { + pType = ConfigParameter + for k, v := range obj.(*corev1.ConfigMap).Data { + data[k] = v + } + } + + if len(params) > 0 { + for _, pp := range params { + paramsByKey[pp.Key].Value = string(data[pp.FromKey]) + } + } else { + for kk, vv := range data { + // TODO TO FIX + if paramsByKey[kk] == nil { + paramsByKey[kk] = &Parameter{} + + } + paramsByKey[kk].Value = vv + paramsByKey[kk].Key = kk + // TODO This would be checked if we want to recreate the data or just mount the whole secret + paramsByKey[kk].MountType = MountEnvFile + paramsByKey[kk].Type = pType + } + } + + return nil +} diff --git a/application/settings/settings.go b/application/settings/settings.go index 4b2db5b..d617686 100644 --- a/application/settings/settings.go +++ b/application/settings/settings.go @@ -62,11 +62,9 @@ func GetObjects(s Settings) map[int]objects.Object { meta.SetObjectMeta(s.GetConfigMapMeta(), cm.ObjectMeta) meta.SetObjectMeta(s.GetSecretMeta(), secret.ObjectMeta) - // TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS params := s.GetConfig() for _, p := range *params.GetParameters() { - // TODO check not mountLiteral ?? if p.MountType == parameters.MountEnvFile && p.Type == parameters.SecretParameter && len(p.Value) > 0 { diff --git a/go.mod b/go.mod index deb8583..28fa277 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,9 @@ module k8s.libre.sh go 1.13 require ( + github.com/golangci/golangci-lint v1.27.0 // indirect github.com/onsi/ginkgo v1.12.0 - github.com/onsi/gomega v1.8.1 + github.com/onsi/gomega v1.9.0 github.com/presslabs/controller-util v0.2.2 golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 // indirect k8s.io/api v0.18.1 diff --git a/go.sum b/go.sum index 9d40e0c..d0b0c39 100644 --- a/go.sum +++ b/go.sum @@ -10,14 +10,21 @@ github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxB github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc= github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157 h1:hY39LwQHh+1kaovmIjOrlqnXNX6tygSRfLkkK33IkZU= +github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/OpenPeeDeeP/depguard v1.0.1 h1:VlW4R6jmBIv3/u1JNlawEvJMM4J+dPORPaZasQee8Us= +github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -31,9 +38,13 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/blang/semver v3.5.0+incompatible h1:CGxCgetQ64DKk7rdZ++Vfnb1+ogGNnB17OJKJXD2Cfs= github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bombsimon/wsl/v3 v3.0.0 h1:w9f49xQatuaeTJFaNP4SpiWSR5vfT6IstPtM62JjcqA= +github.com/bombsimon/wsl/v3 v3.0.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/coreos/bbolt v1.3.1-coreos.6/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.15+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= @@ -44,13 +55,16 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -65,6 +79,7 @@ github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M= github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -72,12 +87,18 @@ github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2H github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= +github.com/go-critic/go-critic v0.4.1 h1:4DTQfT1wWwLg/hzxwD9bkdhDQrdJtxe6DUTadPlrIeE= +github.com/go-critic/go-critic v0.4.1/go.mod h1:7/14rZGnZbY6E38VEGk2kVhoq6itzc1E68facVDK23g= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0= +github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/zapr v0.1.0 h1:h+WVe9j6HAA01niTJPA/kKH0i7e0rLZBCwauQFcRE54= github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= +github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= @@ -121,9 +142,35 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g= +github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4= +github.com/go-toolsmith/astcopy v1.0.0 h1:OMgl1b1MEpjFQ1m5ztEO06rz5CUd3oBv9RF7+DyvdG8= +github.com/go-toolsmith/astcopy v1.0.0/go.mod h1:vrgyG+5Bxrnz4MZWPF+pI4R8h3qKRjjyvV/DSez4WVQ= +github.com/go-toolsmith/astequal v0.0.0-20180903214952-dcb477bfacd6/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= +github.com/go-toolsmith/astequal v1.0.0 h1:4zxD8j3JRFNyLN46lodQuqz3xdKSrur7U/sr0SDS/gQ= +github.com/go-toolsmith/astequal v1.0.0/go.mod h1:H+xSiq0+LtiDC11+h1G32h7Of5O3CYFJ99GVbS5lDKY= +github.com/go-toolsmith/astfmt v0.0.0-20180903215011-8f8ee99c3086/go.mod h1:mP93XdblcopXwlyN4X4uodxXQhldPGZbcEJIimQHrkg= +github.com/go-toolsmith/astfmt v1.0.0 h1:A0vDDXt+vsvLEdbMFJAUBI/uTbRw1ffOPnxsILnFL6k= +github.com/go-toolsmith/astfmt v1.0.0/go.mod h1:cnWmsOAuq4jJY6Ct5YWlVLmcmLMn1JUPuQIHCY7CJDw= +github.com/go-toolsmith/astinfo v0.0.0-20180906194353-9809ff7efb21/go.mod h1:dDStQCHtmZpYOmjRP/8gHHnCCch3Zz3oEgCdZVdtweU= +github.com/go-toolsmith/astp v0.0.0-20180903215135-0af7e3c24f30/go.mod h1:SV2ur98SGypH1UjcPpCatrV5hPazG6+IfNHbkDXBRrk= +github.com/go-toolsmith/astp v1.0.0 h1:alXE75TXgcmupDsMK1fRAy0YUzLzqPVvBKoyWV+KPXg= +github.com/go-toolsmith/astp v1.0.0/go.mod h1:RSyrtpVlfTFGDYRbrjyWP1pYu//tSFcvdYrA8meBmLI= +github.com/go-toolsmith/pkgload v0.0.0-20181119091011-e9e65178eee8/go.mod h1:WoMrjiy4zvdS+Bg6z9jZH82QXwkcgCBX6nOfnmdaHks= +github.com/go-toolsmith/pkgload v1.0.0/go.mod h1:5eFArkbO80v7Z0kdngIxsRXRMTaX4Ilcwuh3clNrQJc= +github.com/go-toolsmith/strparse v1.0.0 h1:Vcw78DnpCAKlM20kSbAyO4mPfJn/lyYA4BJUDxe2Jb4= +github.com/go-toolsmith/strparse v1.0.0/go.mod h1:YI2nUKP9YGZnL/L1/DLFBfixrcjslWct4wyljWhSRy8= +github.com/go-toolsmith/typep v1.0.0 h1:zKymWyA1TRYvqYrYDrfEMZULyrhcnGY3x7LDKU2XQaA= +github.com/go-toolsmith/typep v1.0.0/go.mod h1:JSQCQMUPdRlMZFswiq3TGpNp1GMktqkR2Ns5AIQkATU= +github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gofrs/flock v0.0.0-20190320160742-5135e617513b h1:ekuhfTjngPhisSjOJ0QWKpPQE8/rbknHaes6WVJj5Hw= +github.com/gofrs/flock v0.0.0-20190320160742-5135e617513b/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= @@ -132,6 +179,7 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -142,6 +190,36 @@ github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2 h1:23T5iq8rbUYlhpt5DB4XJkc6BU31uODLD1o1gKvZmD0= +github.com/golangci/check v0.0.0-20180506172741-cfe4005ccda2/go.mod h1:k9Qvh+8juN+UKMCS/3jFtGICgW8O96FVaZsaxdzDkR4= +github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a h1:w8hkcTqaFpzKqonE9uMCefW1WDie15eSP/4MssdenaM= +github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a/go.mod h1:ryS0uhF+x9jgbj/N71xsEqODy9BN81/GonCZiOzirOk= +github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6 h1:YYWNAGTKWhKpcLLt7aSj/odlKrSrelQwlovBpDuf19w= +github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6/go.mod h1:DbHgvLiFKX1Sh2T1w8Q/h4NAI8MHIpzCdnBUDTXU3I0= +github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613 h1:9kfjN3AdxcbsZBf8NjltjWihK2QfBBBZuv91cMFfDHw= +github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613/go.mod h1:SyvUF2NxV+sN8upjjeVYr5W7tyxaT1JVtvhKhOn2ii8= +github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3 h1:pe9JHs3cHHDQgOFXJJdYkK6fLz2PWyYtP4hthoCMvs8= +github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3/go.mod h1:JXrF4TWy4tXYn62/9x8Wm/K/dm06p8tCKwFRDPZG/1o= +github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee h1:J2XAy40+7yz70uaOiMbNnluTg7gyQhtGqLQncQh+4J8= +github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee/go.mod h1:ozx7R9SIwqmqf5pRP90DhR2Oay2UIjGuKheCBCNwAYU= +github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a h1:iR3fYXUjHCR97qWS8ch1y9zPNsgXThGwjKPrYfqMPks= +github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU= +github.com/golangci/golangci-lint v1.27.0 h1:VYLx63qb+XJsHdZ27PMS2w5JZacN0XG8ffUwe7yQomo= +github.com/golangci/golangci-lint v1.27.0/go.mod h1:+eZALfxIuthdrHPtfM7w/R3POJLjHDfJJw8XZl9xOng= +github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc h1:gLLhTLMk2/SutryVJ6D4VZCU3CUqr8YloG7FPIBWFpI= +github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU= +github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA= +github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg= +github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA= +github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca/go.mod h1:tvlJhZqDe4LMs4ZHD0oMUlt9G2LWuDGoisJTBzLMV9o= +github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770 h1:EL/O5HGrF7Jaq0yNhBLucz9hTuRzj2LdwGBOaENgxIk= +github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770/go.mod h1:dEbvlSfYbMQDtrpRMQU675gSDLDNa8sCPPChZ7PhiVA= +github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21 h1:leSNB7iYzLYSSx3J/s5sVf4Drkc68W2wm4Ixh/mr0us= +github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21/go.mod h1:tf5+bzsHdTM0bsB7+8mt0GUMvjCgwLpTapNZHU8AajI= +github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0 h1:HVfrLniijszjS1aiNg8JbBMO2+E1WIQ+j/gL4SQqGPg= +github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0/go.mod h1:qOQCunEYvmd/TLamH+7LlVccLvUH5kZNhbCgTHoBbp4= +github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSWhqsYNgcuWO2kFlpdOZbP0+yRjmvPGys= +github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -154,6 +232,7 @@ github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -161,18 +240,25 @@ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsC github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk= github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU= +github.com/gookit/color v1.2.4/go.mod h1:AhIE+pS6D4Ql0SQWbBeXPHw7gY0/sjHoA4s/n1KB7xg= github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3 h1:JVnpOZS+qxli+rgVl98ILOXVNbW+kb5wcxeGx8ShUIw= +github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE= github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v0.0.0-20190222133341-cfaf5686ec79/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.3.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -182,7 +268,13 @@ github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a h1:GmsqmapfzSJkm28dhRoHz2tLRbJmqhU86IPgBtN3mmk= +github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a/go.mod h1:xRskid8CManxVta/ALEhJha/pweKBaVG6fWgc0yH25s= +github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3 h1:jNYPNLe3d8smommaoQlK7LOA5ESyUJJ+Wf79ZtA7Vp4= +github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3/go.mod h1:HEWGJkRDzjJY2sqdDwxccsGicWEf9BQOZsq2tV+xzM0= +github.com/jmoiron/sqlx v1.2.1-0.20190826204134-d7d95172beb5/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -190,10 +282,17 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -202,19 +301,37 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= +github.com/maratori/testpackage v1.0.1 h1:QtJ5ZjqapShm0w5DosRjg0PRlSdAdlx+W6cCKoALdbQ= +github.com/maratori/testpackage v1.0.1/go.mod h1:ddKdw+XG0Phzhx8BFDTKgpWP4i7MpApTE5fXSKAqwDU= +github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb h1:RHba4YImhrUVQDHUCe2BNSOz4tVy2yGyXhvYDvxGgeE= +github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-ps v0.0.0-20190716172923-621e5597135b/go.mod h1:r1VsdOzOPt1ZSrGZWFoNhsAedKnEd6r9Np1+5blZCWk= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= @@ -223,10 +340,17 @@ github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lN github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mozilla/tls-observatory v0.0.0-20200317151703-4fa42e1c2dee/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/nakabonne/nestif v0.3.0 h1:+yOViDGhg8ygGrmII72nV9B/zGxY188TYpfolntsaPw= +github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c= +github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E= +github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.4.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -246,9 +370,13 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.8.1 h1:C5Dqfs/LeauYDX0jJXIe2SWmwCbGzx9yF8C8xy3Lh34= github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= +github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg= +github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= +github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -260,31 +388,56 @@ github.com/presslabs/controller-util v0.2.2 h1:1AOTpk4kQHzu3hp07JiFrXmpF6i0+oQBH github.com/presslabs/controller-util v0.2.2/go.mod h1:nPUlgmBbMD+9nWnyF/rgx0yfistieUfcbqRtcqJrK6A= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0 h1:vrDKnkGzuGvhNAL56c7DBz29ZL+KxnoR0x7enabFceM= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/ryancurrah/gomodguard v1.0.4 h1:oCreMAt9GuFXDe9jW4HBpc3GjdX3R/sUEcLAGh1zPx8= +github.com/ryancurrah/gomodguard v1.0.4/go.mod h1:9T/Cfuxs5StfsocWr4WzDL36HqnX0fVb9d5fSEaLhoE= +github.com/securego/gosec/v2 v2.3.0 h1:y/9mCF2WPDbSDpL3QDWZD3HHGrSYw0QSHnCqTfs4JPE= +github.com/securego/gosec/v2 v2.3.0/go.mod h1:UzeVyUXbxukhLeHKV3VVqo7HdoQR9MrRfFmZYotn8ME= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc= +github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= +github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= +github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/sourcegraph/go-diff v0.5.1 h1:gO6i5zugwzo1RVTvgvfwCOSVegNuvnNi6bAD1QCmkHs= +github.com/sourcegraph/go-diff v0.5.1/go.mod h1:j2dHj3m8aZgQO8lMTcTnBcXkRRRqi34cd2MNlA9u1mE= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= @@ -292,22 +445,52 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk= +github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ= +github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM= +github.com/tetafro/godot v0.3.7 h1:+mecr7RKrUKB5UQ1gwqEMn13sDKTyDR8KNIquB9mm+8= +github.com/tetafro/godot v0.3.7/go.mod h1:/7NLHhv08H1+8DNj0MElpAACw1ajsCuf3TKNQxA5S+0= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q= +github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa h1:RC4maTWLKKwb7p1cnoygsbKIgNlJqSYBeAFON3Ar8As= +github.com/tommy-muehle/go-mnd v1.3.1-0.20200224220436-e6f9a994e8fa/go.mod h1:dSUh0FtTP8VhvkL1S+gUR1OKd9ZnSaozuI6r3m6wOig= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ultraware/funlen v0.0.2 h1:Av96YVBwwNSe4MLR7iI/BIa3VyI7/djnto/pK3Uxbdo= +github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= +github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFODYDsg= +github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/uudashr/gocognit v1.0.1 h1:MoG2fZ0b/Eo7NXoIwCVFLG5JED3qgQz5/NEE+rOsjPs= +github.com/uudashr/gocognit v1.0.1/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= +github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOVRUAfrukLPuGJ4= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.mongodb.org/mongo-driver v1.0.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= @@ -317,6 +500,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v0.0.0-20180122172545-ddea229ff1df/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= @@ -329,9 +513,11 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1 h1:anGSYQpPhQwXlwsu5wmfq0nWkCNaMEMUwAv13Y92hd8= golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 h1:/Tl7pH94bvbAAHBdZJT947M/+gp0+CqQXDtMRC0fseo= @@ -345,11 +531,15 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180112015858-5ccada7d0a7b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -359,6 +549,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -369,6 +560,8 @@ golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ym golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk= golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -390,6 +583,7 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190209173611-3b5209105503/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -413,24 +607,45 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181117154741-2ddaf7f79a09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190110163146-51295c7ec13a/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190221204921-83362c3779f5/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200324003944-a576cf524670/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200331202046-9d5940d49312/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200414032229-332987a829c3/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770 h1:M9Fif0OxNji8w+HvmhVQ8KJtiZOsjU9RgslJGhn95XE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.0.1/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU= gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0= gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw= @@ -447,6 +662,7 @@ google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= @@ -455,12 +671,16 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= @@ -478,6 +698,8 @@ gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= k8s.io/api v0.0.0-20190918155943-95b840bb6a1f/go.mod h1:uWuOHnjmNrtQomJrvEBg0c0HRNyQ+8KTEERVsK0PW48= k8s.io/api v0.17.2/go.mod h1:BS9fjjLc4CMuqfSO8vgbHPKMt5+SF0ET6u/RVDihTo4= k8s.io/api v0.18.1 h1:pnHr0LH69kvL29eHldoepUDKTuiOejNZI2A1gaxve3Q= @@ -522,6 +744,12 @@ modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs= modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= +mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I= +mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= +mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphDJbHOQO1DFFFTeBo= +mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= +mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4= +mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw= sigs.k8s.io/controller-runtime v0.4.0 h1:wATM6/m+3w8lj8FXNaO6Fs/rq/vqoOjO1Q116Z9NPsg= sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns= sigs.k8s.io/controller-runtime v0.5.0 h1:CbqIy5fbUX+4E9bpnBFd204YAzRYlM9SWW77BbrcDQo= @@ -539,3 +767,5 @@ sigs.k8s.io/testing_frameworks v0.1.2/go.mod h1:ToQrwSC3s8Xf/lADdZp3Mktcql9CG0UA sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= +sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4 h1:JPJh2pk3+X4lXAkZIk2RuE/7/FoK9maXw+TNPJhVS/c= +sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0= diff --git a/meta/instance.go b/meta/instance.go index f4e61a5..8cc6fc2 100644 --- a/meta/instance.go +++ b/meta/instance.go @@ -58,7 +58,7 @@ func InstanceLabels(m Instance) map[string]string { return labels } -// TODO user Object interface and rename Merge ? +// TODO use Object interface and rename Merge ? func SetObjectMeta(src Instance, dest Instance) { dest.SetLabels(labels.Merge(dest.GetLabels(), InstanceLabels(src))) diff --git a/objects/secret/mutate.go b/objects/secret/mutate.go index 51cc1b0..a99787e 100644 --- a/objects/secret/mutate.go +++ b/objects/secret/mutate.go @@ -34,7 +34,7 @@ func MutateSecret(r Mutate, obj *corev1.Secret, m meta.Meta) error { if len(data) > 0 { for k, v := range data { - // TODO IMPROVE SECRET GENERATION CYCLE + // TODO IMPROVE SECRET GENERATION CYCLE, only generated secrets should not be updated unless asked for if len(obj.Data[k]) == 0 { obj.Data[k] = []byte(v) -- GitLab From e2d851dc53ddff08e1046988526038a7ebad2754 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 17:17:41 +0200 Subject: [PATCH 07/18] fixes --- objects/container/object.go | 18 +++---- objects/container/zz_generated.deepcopy.go | 56 +++++++++++----------- objects/deployment/deployment.go | 35 +++++++++----- objects/object.go | 2 +- objects/pod/mutate.go | 15 ++---- objects/pod/object.go | 4 +- utils/utils.go | 1 + 7 files changed, 69 insertions(+), 62 deletions(-) diff --git a/objects/container/object.go b/objects/container/object.go index 793f4be..d08c4b1 100644 --- a/objects/container/object.go +++ b/objects/container/object.go @@ -28,12 +28,12 @@ import ( // // +kubebuilder:object:generate=true type Container struct { - *TemplateSpec `json:",inline"` + *ContainerSpec `json:",inline"` *parameters.ConfigSpec `json:"parameters,omitempty"` } // +kubebuilder:object:generate=true -type TemplateSpec struct { +type ContainerSpec struct { // Name of the container specified as a DNS_LABEL. // Each container in a pod must have a unique name (DNS_LABEL). // Cannot be updated. @@ -96,10 +96,10 @@ type Probes struct { LivenessProbe *corev1.Probe `json:"livenessProbe,omitempty" protobuf:"bytes,10,opt,name=livenessProbe"` } -func (r *TemplateSpec) GetContainerImage() string { return r.Image } -func (r *TemplateSpec) GetContainerName() string { return r.Name } -func (r *TemplateSpec) GetContainerImagePullPolicy() corev1.PullPolicy { return r.ImagePullPolicy } -func (r *TemplateSpec) GetContainerPorts() []corev1.ContainerPort { return r.Ports } -func (r *TemplateSpec) GetContainerLivenessProbe() *corev1.Probe { return r.LivenessProbe } -func (r *TemplateSpec) GetContainerReadinessProbe() *corev1.Probe { return r.ReadinessProbe } -func (r *TemplateSpec) GetContainerArgs() []string { return r.Args } +func (c *ContainerSpec) GetContainerImage() string { return c.Image } +func (c *ContainerSpec) GetContainerName() string { return c.Name } +func (c *ContainerSpec) GetContainerImagePullPolicy() corev1.PullPolicy { return c.ImagePullPolicy } +func (c *ContainerSpec) GetContainerPorts() []corev1.ContainerPort { return c.Ports } +func (c *ContainerSpec) GetContainerLivenessProbe() *corev1.Probe { return c.LivenessProbe } +func (c *ContainerSpec) GetContainerReadinessProbe() *corev1.Probe { return c.ReadinessProbe } +func (c *ContainerSpec) GetContainerArgs() []string { return c.Args } diff --git a/objects/container/zz_generated.deepcopy.go b/objects/container/zz_generated.deepcopy.go index 775593f..bc8a234 100644 --- a/objects/container/zz_generated.deepcopy.go +++ b/objects/container/zz_generated.deepcopy.go @@ -26,9 +26,9 @@ import ( // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Container) DeepCopyInto(out *Container) { *out = *in - if in.TemplateSpec != nil { - in, out := &in.TemplateSpec, &out.TemplateSpec - *out = new(TemplateSpec) + if in.ContainerSpec != nil { + in, out := &in.ContainerSpec, &out.ContainerSpec + *out = new(ContainerSpec) (*in).DeepCopyInto(*out) } if in.ConfigSpec != nil { @@ -48,52 +48,52 @@ func (in *Container) DeepCopy() *Container { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Probes) DeepCopyInto(out *Probes) { +func (in *ContainerSpec) DeepCopyInto(out *ContainerSpec) { *out = *in - if in.ReadinessProbe != nil { - in, out := &in.ReadinessProbe, &out.ReadinessProbe - *out = new(v1.Probe) - (*in).DeepCopyInto(*out) + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make([]string, len(*in)) + copy(*out, *in) } - if in.LivenessProbe != nil { - in, out := &in.LivenessProbe, &out.LivenessProbe - *out = new(v1.Probe) - (*in).DeepCopyInto(*out) + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]v1.ContainerPort, len(*in)) + copy(*out, *in) } + in.Probes.DeepCopyInto(&out.Probes) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Probes. -func (in *Probes) DeepCopy() *Probes { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerSpec. +func (in *ContainerSpec) DeepCopy() *ContainerSpec { if in == nil { return nil } - out := new(Probes) + out := new(ContainerSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateSpec) DeepCopyInto(out *TemplateSpec) { +func (in *Probes) DeepCopyInto(out *Probes) { *out = *in - if in.Args != nil { - in, out := &in.Args, &out.Args - *out = make([]string, len(*in)) - copy(*out, *in) + if in.ReadinessProbe != nil { + in, out := &in.ReadinessProbe, &out.ReadinessProbe + *out = new(v1.Probe) + (*in).DeepCopyInto(*out) } - if in.Ports != nil { - in, out := &in.Ports, &out.Ports - *out = make([]v1.ContainerPort, len(*in)) - copy(*out, *in) + if in.LivenessProbe != nil { + in, out := &in.LivenessProbe, &out.LivenessProbe + *out = new(v1.Probe) + (*in).DeepCopyInto(*out) } - in.Probes.DeepCopyInto(&out.Probes) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateSpec. -func (in *TemplateSpec) DeepCopy() *TemplateSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Probes. +func (in *Probes) DeepCopy() *Probes { if in == nil { return nil } - out := new(TemplateSpec) + out := new(Probes) in.DeepCopyInto(out) return out } diff --git a/objects/deployment/deployment.go b/objects/deployment/deployment.go index 89c3b36..f0a6a2f 100644 --- a/objects/deployment/deployment.go +++ b/objects/deployment/deployment.go @@ -30,8 +30,12 @@ import ( // // +kubebuilder:object:generate=true type Deployment struct { + // Standard object metadata. + // +optional *meta.ObjectMeta `json:"meta,omitempty"` - *DeploymentSpec `json:",inline"` + // Specification of the desired behavior of the Deployment. + // +optional + *DeploymentSpec `json:",inline"` } // DeploymentSpec is the specification of the desired behavior of the DeploymentSpec. @@ -47,37 +51,44 @@ type DeploymentSpec struct { // The deployment strategy to use to replace existing pods with new ones. // +optional // +patchStrategy=retainKeys - Strategy appsv1.DeploymentStrategy `json:"strategy,omitempty"` + Strategy appsv1.DeploymentStrategy `json:"strategy,omitempty"` + // PodSpec describes the pods that will be created. *pod.PodSpec `json:",inline"` } -func (r *DeploymentSpec) GetReplicas() *int32 { - return r.Replicas +func (spec *DeploymentSpec) GetReplicas() *int32 { + return spec.Replicas } -func (r *DeploymentSpec) GetDeploymentStrategy() appsv1.DeploymentStrategy { - return r.Strategy +func (spec *DeploymentSpec) GetDeploymentStrategy() appsv1.DeploymentStrategy { + return spec.Strategy } func (o *Deployment) GetObject() interfaces.Object { return &appsv1.Deployment{} } -func (w *Deployment) Mutate(obj interfaces.Object) error { +func (o *Deployment) Mutate(obj interfaces.Object) error { deploy := obj.(*appsv1.Deployment) - w.PodSpec.ObjectMeta = w.ObjectMeta + o.PodSpec.ObjectMeta = o.ObjectMeta - MutateDeployment(w, deploy) + err := MutateDeployment(o, deploy) + if err != nil { + return err + } - meta.MutateMeta(w.ObjectMeta, obj) + err = meta.MutateMeta(o.ObjectMeta, obj) + if err != nil { + return err + } deploy.Spec.Template.ObjectMeta.Name = deploy.ObjectMeta.Name - deploy.Spec.Template.ObjectMeta.Labels = w.ObjectMeta.Labels + deploy.Spec.Template.ObjectMeta.Labels = o.ObjectMeta.Labels - deploy.Spec.Selector = metav1.SetAsLabelSelector(w.ObjectMeta.Labels) + deploy.Spec.Selector = metav1.SetAsLabelSelector(o.ObjectMeta.Labels) return nil } diff --git a/objects/object.go b/objects/object.go index d7e7093..cc6f705 100644 --- a/objects/object.go +++ b/objects/object.go @@ -16,7 +16,7 @@ limitations under the License. // Objects package contains core kubernetes resources definitions that can be included in an application CRD. // The definitions are stripped down version with only specs that should be user-defined. // -// Every objects definied in this package implements its own interface which can mutates its associated kubernetes resource. +// Every objects definied in this package implements a mutate interface which can create or update its associated kubernetes resource. // // All those objects also implements the Object inteface from which we can create an object syncer - see https://github.com/presslabs/controller-util/syncer package objects diff --git a/objects/pod/mutate.go b/objects/pod/mutate.go index 20a8ff6..d24a204 100644 --- a/objects/pod/mutate.go +++ b/objects/pod/mutate.go @@ -38,7 +38,7 @@ func MutatePod(r Mutate, obj *corev1.PodTemplateSpec) error { containerList := []corev1.Container{} obj.Spec.SecurityContext = r.GetPodSecurityContext() - //& obj.Spec.Volumes = r.GetPodVolumes() + // obj.Spec.Volumes = r.GetPodVolumes() obj.Spec.RestartPolicy = r.GetPodRestartPolicy() obj.Spec.NodeSelector = r.GetPodNodeSelector() obj.Spec.Affinity = r.GetPodAffinity() @@ -46,24 +46,19 @@ func MutatePod(r Mutate, obj *corev1.PodTemplateSpec) error { containers := r.GetContainers() if len(containers) > 0 { - /* MutateContainer(r, container) - containerList = append(containerList, *container) - obj.Spec.Containers = containerList - */ for k, c := range containers { if len(obj.Spec.Containers) == 0 { container.MutateContainer(c, containerSpec) containerList = append(containerList, *containerSpec) obj.Spec.Containers = containerList } else { + // TODO FIX mutate container by name ? container.MutateContainer(c, &obj.Spec.Containers[k]) } } - } /* else { - // for k, c := range containers { - // MutateContainer(c, &obj.Spec.Containers[k]) - // } - // } */ + } + + // TODO add init containers if r.GetPodSecurityContext() != nil { diff --git a/objects/pod/object.go b/objects/pod/object.go index 44d8f1c..880842f 100644 --- a/objects/pod/object.go +++ b/objects/pod/object.go @@ -111,8 +111,8 @@ func (o *PodSpec) Mutate(obj interfaces.Object) error { } func (spec *PodSpec) GetContainers() []container.Mutate { - if len(spec.Container.TemplateSpec.Name) == 0 { - spec.Container.TemplateSpec.Name = spec.ObjectMeta.GetComponent() + if len(spec.Container.ContainerSpec.Name) == 0 { + spec.Container.ContainerSpec.Name = spec.ObjectMeta.GetComponent() } containers := []container.Mutate{} diff --git a/utils/utils.go b/utils/utils.go index 200ac95..c7c0468 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,6 +15,7 @@ limitations under the License. package utils +// Uniquer returns a unique list of strings func Unique(stringSlice []string) []string { keys := make(map[string]bool) list := []string{} -- GitLab From 931a4590c2fbb0b28c41df57209ad187c6fbd1ba Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 19:23:53 +0200 Subject: [PATCH 08/18] fix sort params by fromKey or key + fixes --- application/settings/component.go | 11 +-- application/settings/parameters/utils.go | 30 +++++-- q | 107 +++++++++++++++++++++++ 3 files changed, 130 insertions(+), 18 deletions(-) create mode 100644 q diff --git a/application/settings/component.go b/application/settings/component.go index 650bacc..e2168bf 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -37,14 +37,6 @@ type Component struct { *ConfigSpec `json:",inline"` } -/* -type Component struct { - *meta.ObjectMeta `json:"commonMeta,omitempty"` - Secrets map[string]configmap.ConfigMap - Configs map[string]secret.Secret - // TemplateValues string -} -*/ func (s *Component) GetConfig() Config { return s.ConfigSpec } func (s *Component) GetMeta() meta.Instance { return s.CommonMeta } @@ -119,8 +111,9 @@ func (s *Component) Init(c client.Client) error { return nil } -// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace +// InitParametersValueFrom intialise the parameters with values provided in external resources in the same namespace // All parameters values are filled from those resources +// Only Secrets and Configmaps are supported func InitParametersValueFrom(s *Component, c client.Client) error { params := parameters.Parameters{} diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index c9409d3..9a63786 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -17,6 +17,8 @@ package parameters import ( "context" + "errors" + "fmt" "reflect" corev1 "k8s.io/api/core/v1" @@ -67,7 +69,12 @@ func ParametersByKey(p *Parameters) map[string]*Parameter { paramsByKey := map[string]*Parameter{} for _, param := range *p { - paramsByKey[param.Key] = param + if len(param.FromKey) > 0 { + paramsByKey[param.FromKey] = param + + } else { + paramsByKey[param.Key] = param + } } return paramsByKey } @@ -100,36 +107,41 @@ func GetAndMergeParameters( return err } - // switch obj.GetObjectKind().GroupVersionKind().Kind - - if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { + switch obj.GetObjectKind().GroupVersionKind().Kind { + case "Secret": pType = SecretParameter for k, v := range obj.(*corev1.Secret).Data { data[k] = string(v) } - } - if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { + case "ConfigMap": pType = ConfigParameter for k, v := range obj.(*corev1.ConfigMap).Data { data[k] = v } + default: + return errors.New("object kind should be ConfigMap or Secret") } if len(params) > 0 { for _, pp := range params { - paramsByKey[pp.Key].Value = string(data[pp.FromKey]) + fmt.Println(pp.FromKey) + /* for kkk, vvv := range paramsByKey { + fmt.Println(kkk) + fmt.Println(vvv) + } */ + paramsByKey[pp.FromKey].Value = string(data[pp.FromKey]) } } else { for kk, vv := range data { - // TODO TO FIX if paramsByKey[kk] == nil { paramsByKey[kk] = &Parameter{} } paramsByKey[kk].Value = vv paramsByKey[kk].Key = kk - // TODO This would be checked if we want to recreate the data or just mount the whole secret + // TODO TO FIX This should be checked if we want to recreate the data or just mount the whole secret paramsByKey[kk].MountType = MountEnvFile + // TODO TO FIX This should be checked paramsByKey[kk].Type = pType } } diff --git a/q b/q new file mode 100644 index 0000000..d606c25 --- /dev/null +++ b/q @@ -0,0 +1,107 @@ +diff --git a/application/settings/component.go b/application/settings/component.go +index 650bacc..e2168bf 100644 +--- a/application/settings/component.go ++++ b/application/settings/component.go +@@ -37,14 +37,6 @@ type Component struct { + *ConfigSpec `json:",inline"` + } +  +-/* +-type Component struct { +- *meta.ObjectMeta `json:"commonMeta,omitempty"` +- Secrets map[string]configmap.ConfigMap +- Configs map[string]secret.Secret +- // TemplateValues string +-} +-*/ + func (s *Component) GetConfig() Config { return s.ConfigSpec } +  + func (s *Component) GetMeta() meta.Instance { return s.CommonMeta } +@@ -119,8 +111,9 @@ func (s *Component) Init(c client.Client) error { + return nil + } +  +-// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace ++// InitParametersValueFrom intialise the parameters with values provided in external resources in the same namespace + // All parameters values are filled from those resources ++// Only Secrets and Configmaps are supported + func InitParametersValueFrom(s *Component, c client.Client) error { +  + params := parameters.Parameters{} +diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go +index c9409d3..9a63786 100644 +--- a/application/settings/parameters/utils.go ++++ b/application/settings/parameters/utils.go +@@ -17,6 +17,8 @@ package parameters +  + import ( + "context" ++ "errors" ++ "fmt" + "reflect" +  + corev1 "k8s.io/api/core/v1" +@@ -67,7 +69,12 @@ func ParametersByKey(p *Parameters) map[string]*Parameter { + paramsByKey := map[string]*Parameter{} +  + for _, param := range *p { +- paramsByKey[param.Key] = param ++ if len(param.FromKey) > 0 { ++ paramsByKey[param.FromKey] = param ++ ++ } else { ++ paramsByKey[param.Key] = param ++ } + } + return paramsByKey + } +@@ -100,36 +107,41 @@ func GetAndMergeParameters( + return err + } +  +- // switch obj.GetObjectKind().GroupVersionKind().Kind +- +- if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { ++ switch obj.GetObjectKind().GroupVersionKind().Kind { ++ case "Secret": + pType = SecretParameter + for k, v := range obj.(*corev1.Secret).Data { + data[k] = string(v) + } +- } +- if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { ++ case "ConfigMap": + pType = ConfigParameter + for k, v := range obj.(*corev1.ConfigMap).Data { + data[k] = v + } ++ default: ++ return errors.New("object kind should be ConfigMap or Secret") + } +  + if len(params) > 0 { + for _, pp := range params { +- paramsByKey[pp.Key].Value = string(data[pp.FromKey]) ++ fmt.Println(pp.FromKey) ++ /* for kkk, vvv := range paramsByKey { ++ fmt.Println(kkk) ++ fmt.Println(vvv) ++ } */ ++ paramsByKey[pp.FromKey].Value = string(data[pp.FromKey]) + } + } else { + for kk, vv := range data { +- // TODO TO FIX + if paramsByKey[kk] == nil { + paramsByKey[kk] = &Parameter{} +  + } + paramsByKey[kk].Value = vv + paramsByKey[kk].Key = kk +- // TODO This would be checked if we want to recreate the data or just mount the whole secret ++ // TODO TO FIX This should be checked if we want to recreate the data or just mount the whole secret + paramsByKey[kk].MountType = MountEnvFile ++ // TODO TO FIX This should be checked + paramsByKey[kk].Type = pType + } + } -- GitLab From 15b0625a6fa61907517178c7ad284faab0d5eaed Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Thu, 21 May 2020 19:26:54 +0200 Subject: [PATCH 09/18] cleanup --- application/settings/parameters/utils.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index 9a63786..d46be7a 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -18,7 +18,6 @@ package parameters import ( "context" "errors" - "fmt" "reflect" corev1 "k8s.io/api/core/v1" @@ -124,11 +123,6 @@ func GetAndMergeParameters( if len(params) > 0 { for _, pp := range params { - fmt.Println(pp.FromKey) - /* for kkk, vvv := range paramsByKey { - fmt.Println(kkk) - fmt.Println(vvv) - } */ paramsByKey[pp.FromKey].Value = string(data[pp.FromKey]) } } else { -- GitLab From 8e64efaed4b5059eb49e3a0644e226ccd44ccf5c Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Sun, 24 May 2020 00:29:34 +0200 Subject: [PATCH 10/18] add sources & createoptions for settings & fixes --- application/settings/component.go | 142 +++++++++++++++--- application/settings/config.go | 103 +++++++++---- application/settings/interface.go | 9 +- application/settings/parameters/parameter.go | 4 +- .../settings/parameters/parameters_helpers.go | 5 +- application/settings/parameters/utils.go | 14 +- application/settings/settings.go | 3 +- application/settings/utils.go | 50 ++++-- application/settings/zz_generated.deepcopy.go | 15 ++ q | 107 ------------- 10 files changed, 266 insertions(+), 186 deletions(-) delete mode 100644 q diff --git a/application/settings/component.go b/application/settings/component.go index e2168bf..3d5cd77 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -26,15 +26,50 @@ import ( "k8s.libre.sh/objects/secret" ) +const ( + // Generate settings as env variables in a configMap or Secret + GenEnvFile SettingsGenerate = "envFile" +) + +const ( + // Generate settings as env variables in a configMap or Secret + SecretSettings SettingsType = "secret" +) + +type SettingsGenerate string +type SettingsType string + // +kubebuilder:object:generate=true type Component struct { - CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` - SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` - ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` - DefaultType parameters.ParameterType `json:"defaultType,omitempty"` - DefaultMountType parameters.MountType `json:"defaultMountType,omitempty"` - // Template string `json:"template,omitempty"` - *ConfigSpec `json:",inline"` + CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` + SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` + ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + // DefaultType parameters.ParameterType `json:"defaultType,omitempty"` + // DefaultMountType parameters.MountType `json:"defaultMountType,omitempty"` + // Template string json:"template,omitempty"` + Generate SettingsGenerate `json:"generate,omitempty"` + SettingsType SettingsType `json:"type,omitempty"` + *ConfigSpec `json:",inline"` +} + +// ConfigSpec defines a list of parameters and references to resources from which those parameters can be fetched +// Only secrets and configmaps in the same namespace are supported as references +// +kubebuilder:object:generate=true +type SettingsSpec struct { + Sources []Source `json:"sources,omitempty"` + // Parameters is a list of parameters + *parameters.Parameters `json:"parameters,omitempty"` +} + +type CreateOptions struct { + CommonMeta *meta.ObjectMeta `json:"commonMeta,omitempty"` + SecretMeta *meta.ObjectMeta `json:"secretMeta,omitempty"` + ConfigMeta *meta.ObjectMeta `json:"configMeta,omitempty"` + // DefaultType parameters.ParameterType `json:"defaultType,omitempty"` + // DefaultMountType parameters.MountType `json:"defaultMountType,omitempty"` + // Template string json:"template,omitempty"` + Generate SettingsGenerate `json:"generate,omitempty"` + SettingsType SettingsType `json:"type,omitempty"` } func (s *Component) GetConfig() Config { return s.ConfigSpec } @@ -64,6 +99,7 @@ func (s *Component) GetObjects() map[int]objects.Object { objs := make(map[int]objects.Object, 2) for _, p := range *s.ConfigSpec.Parameters { + // TODO TO FIX if p.MountType == parameters.MountEnvFile && p.Type == parameters.SecretParameter && len(p.Value) > 0 { @@ -97,7 +133,7 @@ func (s *Component) Init(c client.Client) error { // TODO TO FIX DUPLICATE WITH SETDEFAULTS meta.SetObjectMeta(s.CommonMeta, s.ConfigMeta) meta.SetObjectMeta(s.CommonMeta, s.SecretMeta) - // TODO ADD SECRET REFS HERE ?? + err := InitParametersValueFrom(s, c) if err != nil { @@ -108,6 +144,10 @@ func (s *Component) Init(c client.Client) error { err = s.InitTemplateValues(parameters.KeyPairValues(s.Parameters)) + if err != nil { + return err + } + return nil } @@ -143,26 +183,88 @@ func InitParametersValueFrom(s *Component, c client.Client) error { } } + secretSrc := Source{ + Ref: s.GetSecretMeta().GetName(), + Type: "secret", + } + configSrc := Source{ + Ref: s.GetSecretMeta().GetName(), + Type: "configmap", + } + + if s.Generate == GenEnvFile { + // s.SecretRefs = []string{s.GetSecretMeta().GetName()} + // s.ConfigRefs = []string{s.GetConfigMapMeta().GetName()} + + s.Sources = []Source{ + secretSrc, + configSrc, + } + + for _, v := range paramsByKey { + v.MountType = parameters.MountEnvFile + v.Ref = "" + params = append(params, v) + } + s.Parameters = ¶ms + + return nil + } + + addSecretSrc := false + addConfigSrc := false + for _, v := range paramsByKey { if v.MountType == parameters.MountEnvFile { - if v.Type == parameters.ConfigParameter { - v.Ref = s.GetConfigMapMeta().GetName() - } - if v.Type == parameters.SecretParameter { - v.Ref = s.GetSecretMeta().GetName() + v.Ref = "" + + if !addConfigSrc && v.Type == parameters.ConfigParameter { + s.Sources = append(s.Sources, configSrc) + addConfigSrc = true + } else if !addSecretSrc && v.Type == parameters.SecretParameter { + s.Sources = append(s.Sources, secretSrc) + addSecretSrc = true } } params = append(params, v) } - // if defaultMountType == EnvFile { - - // } - // TODO FIX THIS we need to check if we want to mount as EnvFile and reset old resources references - s.SecretRefs = []string{} - s.ConfigRefs = []string{} - s.Parameters = ¶ms return nil } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SettingsSpec) DeepCopyInto(out *SettingsSpec) { + *out = *in + if in.Sources != nil { + in, out := &in.Sources, &out.Sources + *out = make([]Source, len(*in)) + copy(*out, *in) + } + if in.Parameters != nil { + in, out := &in.Parameters, &out.Parameters + *out = new(parameters.Parameters) + if **in != nil { + in, out := *in, *out + *out = make([]*parameters.Parameter, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(parameters.Parameter) + **out = **in + } + } + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SettingsSpec. +func (in *SettingsSpec) DeepCopy() *SettingsSpec { + if in == nil { + return nil + } + out := new(SettingsSpec) + in.DeepCopyInto(out) + return out +} diff --git a/application/settings/config.go b/application/settings/config.go index 0225fcd..7682f02 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -35,17 +35,23 @@ package settings import ( corev1 "k8s.io/api/core/v1" "k8s.libre.sh/application/settings/parameters" - "k8s.libre.sh/utils" ) +// +kubebuilder:object:generate=true +type Source struct { + // Ref is the name of a resource in the same namespace + Ref string `json:"ref,omitempty"` + // Type is the type of the resource + // Only Secrets and ConfigMaps are supported + Type string `json:"type,omitempty"` +} + // ConfigSpec defines a list of parameters and references to resources from which those parameters can be fetched // Only secrets and configmaps in the same namespace are supported as references // +kubebuilder:object:generate=true type ConfigSpec struct { - // SecretRefs is a list of secrets in the name namespace - SecretRefs []string `json:"secretRefs,omitempty"` - // ConfigRefs is a list of configmaps in the name namespace - ConfigRefs []string `json:"configRefs,omitempty"` + // Sources is a list of sources for the parameters from kubernetes resources in the same namespace + Sources []Source `json:"sources,omitempty"` // Parameters is a list of parameters *parameters.Parameters `json:"parameters,omitempty"` } @@ -61,35 +67,64 @@ func (c *ConfigSpec) GetParameters() *parameters.Parameters { return c.Parameters } -func (c *ConfigSpec) GetConfigRefs() []string { return c.ConfigRefs } - -func (c *ConfigSpec) SetConfigRefs(refs []string) { c.ConfigRefs = refs } - -func (c *ConfigSpec) GetSecretRefs() []string { return c.SecretRefs } +func (c *ConfigSpec) GetSources() []Source { return c.Sources } -func (c *ConfigSpec) SetSecretRefs(refs []string) { c.SecretRefs = refs } +func (c *ConfigSpec) SetSources(sources []Source) { c.Sources = sources } // GetEnvFrom returns a list of EnvFromSource to populate environment variables in the container. func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { envFroms := []corev1.EnvFromSource{} envFrom := corev1.EnvFromSource{} + src := Source{} for _, p := range *c.Parameters { - if len(p.Ref) > 0 { - if p.MountType == parameters.MountEnvFile { - if p.Type == parameters.ConfigParameter { - c.ConfigRefs = append(c.ConfigRefs, p.Ref) - } else if p.Type != parameters.ObjectFieldParameter { - c.SecretRefs = append(c.SecretRefs, p.Ref) + if p.MountType == parameters.MountEnvFile && len(p.Ref) > 0 { + if p.Type == parameters.ConfigParameter { + src = Source{ + Ref: p.Ref, + Type: string(p.Type), } + c.Sources = append(c.Sources, src) + // c.ConfigRefs = append(c.ConfigRefs, p.Ref) + } else if p.Type == parameters.SecretParameter { + src = Source{ + Ref: p.Ref, + Type: string(p.Type), + } + c.Sources = append(c.Sources, src) + // c.SecretRefs = append(c.SecretRefs, p.Ref) } } } - c.SecretRefs = utils.Unique(c.SecretRefs) - c.ConfigRefs = utils.Unique(c.ConfigRefs) + // c.SecretRefs = utils.Unique(c.SecretRefs) + // c.ConfigRefs = utils.Unique(c.ConfigRefs) + + if len(c.Sources) > 0 { + for _, source := range c.Sources { + if source.Type == "configmap" { + envFrom = corev1.EnvFromSource{ + ConfigMapRef: &corev1.ConfigMapEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: source.Ref, + }, + }, + } + envFroms = append(envFroms, envFrom) + } else if source.Type == "secret" { + envFrom = corev1.EnvFromSource{ + SecretRef: &corev1.SecretEnvSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: source.Ref, + }, + }, + } + envFroms = append(envFroms, envFrom) + } + } + } - if len(c.ConfigRefs) > 0 { + /* if len(c.ConfigRefs) > 0 { for _, configRef := range c.ConfigRefs { envFrom = corev1.EnvFromSource{ ConfigMapRef: &corev1.ConfigMapEnvSource{ @@ -113,7 +148,7 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { } envFroms = append(envFroms, envFrom) } - } + } */ if len(envFroms) > 0 { return envFroms @@ -122,28 +157,32 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { return nil } -// We need to manually change this autogenerated function as it is broken with Paramete drs type, its trying to do new([]*Parameter) instead of new(Parameters) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) { *out = *in - if in.SecretRefs != nil { - in, out := &in.SecretRefs, &out.SecretRefs - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ConfigRefs != nil { - in, out := &in.ConfigRefs, &out.ConfigRefs - *out = make([]string, len(*in)) + if in.Sources != nil { + in, out := &in.Sources, &out.Sources + *out = make([]Source, len(*in)) copy(*out, *in) } if in.Parameters != nil { in, out := &in.Parameters, &out.Parameters *out = new(parameters.Parameters) - (*in).DeepCopyInto(*out) + if **in != nil { + in, out := *in, *out + *out = make([]*parameters.Parameter, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(parameters.Parameter) + **out = **in + } + } + } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigSpec. func (in *ConfigSpec) DeepCopy() *ConfigSpec { if in == nil { return nil diff --git a/application/settings/interface.go b/application/settings/interface.go index f002d5c..be8cb08 100644 --- a/application/settings/interface.go +++ b/application/settings/interface.go @@ -20,15 +20,13 @@ import ( ) type Config interface { - GetConfigRefs() []string - SetConfigRefs([]string) GetParameters() *parameters.Parameters SetParameters(*parameters.Parameters) - GetSecretRefs() []string - SetSecretRefs([]string) InitRandValues() InitTemplateValues(map[string]string) error // InitExternaValues(c client.Client) error + SetSources(sources []Source) + GetSources() (sources []Source) } func MergeSettings(src, dest Config) Config { @@ -36,8 +34,7 @@ func MergeSettings(src, dest Config) Config { if dest == nil { dest = src } else { - dest.SetConfigRefs(append(dest.GetConfigRefs(), src.GetConfigRefs()...)) - dest.SetSecretRefs(append(dest.GetSecretRefs(), src.GetSecretRefs()...)) + dest.SetSources(append(dest.GetSources(), src.GetSources()...)) params := *dest.GetParameters() diff --git a/application/settings/parameters/parameter.go b/application/settings/parameters/parameter.go index 211ed79..92cea70 100644 --- a/application/settings/parameters/parameter.go +++ b/application/settings/parameters/parameter.go @@ -36,7 +36,7 @@ const ( // Parameter is mouned as file in the container path MountFile MountType = "file" // Parameter is mounted as EnvFromSource in the container specs - // Data can be retrieved from the the crds or external resources specified in the paramete envFrom + // Data can be retrieved from the crds or external resources specified in the parameter envFrom // and transformed in a new secret or configmap MountEnvFile MountType = "envFile" ) @@ -61,7 +61,7 @@ type Parameter struct { // or as in the data fied of configmap/secret Key string `json:"key,omitempty"` // Value of the paramater, should not contain secret values - // It can be a template, ParameterType should be template + // If it is a template, ParameterType should be template Value string `json:"value,omitempty"` // ValueFrom when specified indicates the source of the parameter. // Cannot be used if value is not empty. diff --git a/application/settings/parameters/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go index 5ea3c89..4e3a512 100644 --- a/application/settings/parameters/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -86,7 +86,8 @@ func (p *Parameters) GetData() map[string]string { data := make(map[string]string) for _, param := range *p { - if param.MountType == MountEnvFile && + // TODO TO FIX + if (param.MountType == MountEnvFile || param.MountType == "") && param.Type != ObjectFieldParameter && len(param.Value) > 0 { data[param.Key] = param.Value @@ -105,7 +106,7 @@ func (p *Parameters) GetEnvVar() []corev1.EnvVar { for _, param := range *p { envVar, err = param.GetEnvVar() - + // TODO TOFIX if err != nil { } diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index d46be7a..93e46b2 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -53,9 +53,9 @@ func Marshal(i interface{}) (Parameters, error) { parameter.Key = env } - if len(parameter.MountType) == 0 { - parameter.MountType = MountEnvFile - } + // if len(parameter.MountType) == 0 { + // parameter.MountType = MountEnvFile + // } parameters = append(parameters, ¶meter) } @@ -89,6 +89,11 @@ func KeyPairValues(p *Parameters) map[string]string { return data } +func InitParametersFromResources() { + +} + +// TODO SPLIT IN GETPARAMETERSFROMSOURCES AND MERGEPARAMETERSBYKEYS func GetAndMergeParameters( params Parameters, paramsByKey map[string]*Parameter, @@ -133,8 +138,7 @@ func GetAndMergeParameters( } paramsByKey[kk].Value = vv paramsByKey[kk].Key = kk - // TODO TO FIX This should be checked if we want to recreate the data or just mount the whole secret - paramsByKey[kk].MountType = MountEnvFile + // paramsByKey[kk].MountType = MountEnvFile // TODO TO FIX This should be checked paramsByKey[kk].Type = pType } diff --git a/application/settings/settings.go b/application/settings/settings.go index d617686..59437c1 100644 --- a/application/settings/settings.go +++ b/application/settings/settings.go @@ -40,8 +40,7 @@ func NewSettings(s Settings) *Component { SecretMeta: s.GetSecretMeta().(*meta.ObjectMeta), ConfigMeta: s.GetConfigMapMeta().(*meta.ObjectMeta), ConfigSpec: &ConfigSpec{ - ConfigRefs: s.GetConfig().GetConfigRefs(), - SecretRefs: s.GetConfig().GetSecretRefs(), + Sources: s.GetConfig().GetSources(), Parameters: s.GetConfig().GetParameters(), }, } diff --git a/application/settings/utils.go b/application/settings/utils.go index 444d0c9..5f9e359 100644 --- a/application/settings/utils.go +++ b/application/settings/utils.go @@ -17,27 +17,57 @@ package settings import "k8s.libre.sh/application/settings/parameters" -func OrderByResourceRef(s *ConfigSpec) (secrets, configs map[string]parameters.Parameters) { +func OrderByResourceRef(s *ConfigSpec) (secrets, configMaps map[string]parameters.Parameters) { secrets = make(map[string]parameters.Parameters) - configs = make(map[string]parameters.Parameters) + configMaps = make(map[string]parameters.Parameters) + for _, source := range s.Sources { + if source.Type == "secret" { + secrets[source.Ref] = parameters.Parameters{} + } else if source.Type == "configmap" { + configMaps[source.Ref] = parameters.Parameters{} + } + } + + // Then we get the sources that are provided for each parameters and will need a transformation + for _, p := range *s.Parameters { + if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.SecretParameter { + secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p) + } + if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.ConfigParameter { + configMaps[p.ValueFrom.Ref] = append(configMaps[p.ValueFrom.Ref], p) + } + } + + return secrets, configMaps +} + +/* +func OrderBySourceTypeAndRef(s *ConfigSpec) (orderedParams map[string]map[string]parameters.Parameters) { // We order the parameters by secret and configmap sources // First we get the sources provided that should be mounted untouched + // paramsByResourceName = make(map[string]parameters.Parameters) + orderedParams = make(map[string]map[string]parameters.Parameters) + orderedParams["secret"] = make(map[string]parameters.Parameters) + orderedParams["configmap"] = make(map[string]parameters.Parameters) + orderedParams["field"] = make(map[string]parameters.Parameters) + orderedParams["templateValue"] = make(map[string]parameters.Parameters) + for _, ref := range s.SecretRefs { - secrets[ref] = parameters.Parameters{} + orderedParams["secret"][ref] = parameters.Parameters{} } for _, ref := range s.ConfigRefs { - configs[ref] = parameters.Parameters{} + orderedParams["configmap"][ref] = parameters.Parameters{} + } // Then we get the sources that are provided for each parameters and will need a transformation for _, p := range *s.Parameters { - if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.SecretParameter { - secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p) - } - if len(p.ValueFrom.Ref) > 0 && p.Type == parameters.ConfigParameter { - configs[p.ValueFrom.Ref] = append(configs[p.ValueFrom.Ref], p) + if len(p.ValueFrom.Ref) > 0 { + orderedParams[string(p.Type)][p.ValueFrom.Ref] = append(orderedParams[string(p.Type)][p.ValueFrom.Ref], p) + } } - return secrets, configs + return orderedParams } +*/ diff --git a/application/settings/zz_generated.deepcopy.go b/application/settings/zz_generated.deepcopy.go index 3847007..00ff916 100644 --- a/application/settings/zz_generated.deepcopy.go +++ b/application/settings/zz_generated.deepcopy.go @@ -56,3 +56,18 @@ func (in *Component) DeepCopy() *Component { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Source) DeepCopyInto(out *Source) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Source. +func (in *Source) DeepCopy() *Source { + if in == nil { + return nil + } + out := new(Source) + in.DeepCopyInto(out) + return out +} diff --git a/q b/q deleted file mode 100644 index d606c25..0000000 --- a/q +++ /dev/null @@ -1,107 +0,0 @@ -diff --git a/application/settings/component.go b/application/settings/component.go -index 650bacc..e2168bf 100644 ---- a/application/settings/component.go -+++ b/application/settings/component.go -@@ -37,14 +37,6 @@ type Component struct { - *ConfigSpec `json:",inline"` - } -  --/* --type Component struct { -- *meta.ObjectMeta `json:"commonMeta,omitempty"` -- Secrets map[string]configmap.ConfigMap -- Configs map[string]secret.Secret -- // TemplateValues string --} --*/ - func (s *Component) GetConfig() Config { return s.ConfigSpec } -  - func (s *Component) GetMeta() meta.Instance { return s.CommonMeta } -@@ -119,8 +111,9 @@ func (s *Component) Init(c client.Client) error { - return nil - } -  --// InitParametersValueFrom intialise the paremeters with values provided in external resources (secrets and configmaps) in the same namespace -+// InitParametersValueFrom intialise the parameters with values provided in external resources in the same namespace - // All parameters values are filled from those resources -+// Only Secrets and Configmaps are supported - func InitParametersValueFrom(s *Component, c client.Client) error { -  - params := parameters.Parameters{} -diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go -index c9409d3..9a63786 100644 ---- a/application/settings/parameters/utils.go -+++ b/application/settings/parameters/utils.go -@@ -17,6 +17,8 @@ package parameters -  - import ( - "context" -+ "errors" -+ "fmt" - "reflect" -  - corev1 "k8s.io/api/core/v1" -@@ -67,7 +69,12 @@ func ParametersByKey(p *Parameters) map[string]*Parameter { - paramsByKey := map[string]*Parameter{} -  - for _, param := range *p { -- paramsByKey[param.Key] = param -+ if len(param.FromKey) > 0 { -+ paramsByKey[param.FromKey] = param -+ -+ } else { -+ paramsByKey[param.Key] = param -+ } - } - return paramsByKey - } -@@ -100,36 +107,41 @@ func GetAndMergeParameters( - return err - } -  -- // switch obj.GetObjectKind().GroupVersionKind().Kind -- -- if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { -+ switch obj.GetObjectKind().GroupVersionKind().Kind { -+ case "Secret": - pType = SecretParameter - for k, v := range obj.(*corev1.Secret).Data { - data[k] = string(v) - } -- } -- if obj.GetObjectKind().GroupVersionKind().Kind == "ConfigMap" { -+ case "ConfigMap": - pType = ConfigParameter - for k, v := range obj.(*corev1.ConfigMap).Data { - data[k] = v - } -+ default: -+ return errors.New("object kind should be ConfigMap or Secret") - } -  - if len(params) > 0 { - for _, pp := range params { -- paramsByKey[pp.Key].Value = string(data[pp.FromKey]) -+ fmt.Println(pp.FromKey) -+ /* for kkk, vvv := range paramsByKey { -+ fmt.Println(kkk) -+ fmt.Println(vvv) -+ } */ -+ paramsByKey[pp.FromKey].Value = string(data[pp.FromKey]) - } - } else { - for kk, vv := range data { -- // TODO TO FIX - if paramsByKey[kk] == nil { - paramsByKey[kk] = &Parameter{} -  - } - paramsByKey[kk].Value = vv - paramsByKey[kk].Key = kk -- // TODO This would be checked if we want to recreate the data or just mount the whole secret -+ // TODO TO FIX This should be checked if we want to recreate the data or just mount the whole secret - paramsByKey[kk].MountType = MountEnvFile -+ // TODO TO FIX This should be checked - paramsByKey[kk].Type = pType - } - } -- GitLab From 52aa97b33f4511cd5b20aa56837f9616c90cb21e Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Sun, 24 May 2020 00:41:04 +0200 Subject: [PATCH 11/18] fix cm mutate data not erased when parameter is removed --- objects/configmap/mutate.go | 9 ++++++--- objects/secret/mutate.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/objects/configmap/mutate.go b/objects/configmap/mutate.go index 3c326ea..bb18228 100644 --- a/objects/configmap/mutate.go +++ b/objects/configmap/mutate.go @@ -29,14 +29,17 @@ func MutateConfigMap(r Mutate, obj *corev1.ConfigMap, m meta.Meta) error { data := r.GetData() if len(obj.Data) == 0 { - obj.Data = make(map[string]string) + obj.Data = make(map[string]string, len(data)) } - if len(data) > 0 { + // TODO TO FIX data won't be removed if parameter removed + /* if len(data) > 0 { for k, v := range data { obj.Data[k] = v } - } + } */ + + obj.Data = data meta.MutateMeta(m, obj) diff --git a/objects/secret/mutate.go b/objects/secret/mutate.go index a99787e..069b829 100644 --- a/objects/secret/mutate.go +++ b/objects/secret/mutate.go @@ -34,7 +34,7 @@ func MutateSecret(r Mutate, obj *corev1.Secret, m meta.Meta) error { if len(data) > 0 { for k, v := range data { - // TODO IMPROVE SECRET GENERATION CYCLE, only generated secrets should not be updated unless asked for + // TODO TOFIX IMPROVE SECRET GENERATION CYCLE, only generated secrets should not be updated unless asked for if len(obj.Data[k]) == 0 { obj.Data[k] = []byte(v) -- GitLab From 90d45c3296ecdccdf9a4acf609bc7afb54c43b7f Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Sun, 24 May 2020 01:45:50 +0200 Subject: [PATCH 12/18] use annotation for secret generation --- application/settings/component.go | 26 ++++++++++++++++++++++++++ application/settings/config.go | 31 ------------------------------- objects/deployment/deployment.go | 1 + objects/secret/mutate.go | 18 ++++++++++++++---- objects/service/object.go | 1 - 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/application/settings/component.go b/application/settings/component.go index 3d5cd77..863e102 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -16,6 +16,8 @@ limitations under the License. package settings import ( + "strings" + corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -98,20 +100,44 @@ func (s *Component) GetObjects() map[int]objects.Object { objs := make(map[int]objects.Object, 2) + genConfigParams := []string{} + genSecretParams := []string{} + for _, p := range *s.ConfigSpec.Parameters { // TODO TO FIX if p.MountType == parameters.MountEnvFile && p.Type == parameters.SecretParameter && len(p.Value) > 0 { + if p.Generate != parameters.GenerateTemplate && p.Generate != "" { + genSecretParams = append(genSecretParams, p.Key) + } secret.Parameters = append(secret.Parameters, p) } if p.MountType == parameters.MountEnvFile && p.Type == parameters.ConfigParameter && len(p.Value) > 0 { + if p.Generate != parameters.GenerateTemplate && p.Generate != "" { + genConfigParams = append(genConfigParams, p.Key) + } cm.Parameters = append(cm.Parameters, p) } } + if len(genSecretParams) > 0 { + if len(secret.ObjectMeta.Annotations) == 0 { + secret.ObjectMeta.Annotations = make(map[string]string) + } + secret.ObjectMeta.Annotations["settings.k8s.libre.sh/generate"] = strings.Join(genSecretParams, ",") + + } + + if len(genConfigParams) > 0 { + if len(secret.ObjectMeta.Annotations) == 0 { + cm.ObjectMeta.Annotations = make(map[string]string) + } + secret.ObjectMeta.Annotations["settings.k8s.libre.sh/generate"] = strings.Join(genConfigParams, ",") + } + // TODO IMPROVE if len(cm.Parameters) > 0 { objs[0] = cm diff --git a/application/settings/config.go b/application/settings/config.go index 7682f02..b5542ad 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -85,21 +85,16 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { Type: string(p.Type), } c.Sources = append(c.Sources, src) - // c.ConfigRefs = append(c.ConfigRefs, p.Ref) } else if p.Type == parameters.SecretParameter { src = Source{ Ref: p.Ref, Type: string(p.Type), } c.Sources = append(c.Sources, src) - // c.SecretRefs = append(c.SecretRefs, p.Ref) } } } - // c.SecretRefs = utils.Unique(c.SecretRefs) - // c.ConfigRefs = utils.Unique(c.ConfigRefs) - if len(c.Sources) > 0 { for _, source := range c.Sources { if source.Type == "configmap" { @@ -124,32 +119,6 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { } } - /* if len(c.ConfigRefs) > 0 { - for _, configRef := range c.ConfigRefs { - envFrom = corev1.EnvFromSource{ - ConfigMapRef: &corev1.ConfigMapEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: configRef, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - } - - if len(c.SecretRefs) > 0 { - for _, secretRef := range c.SecretRefs { - envFrom = corev1.EnvFromSource{ - SecretRef: &corev1.SecretEnvSource{ - LocalObjectReference: corev1.LocalObjectReference{ - Name: secretRef, - }, - }, - } - envFroms = append(envFroms, envFrom) - } - } */ - if len(envFroms) > 0 { return envFroms } diff --git a/objects/deployment/deployment.go b/objects/deployment/deployment.go index f0a6a2f..48b8757 100644 --- a/objects/deployment/deployment.go +++ b/objects/deployment/deployment.go @@ -72,6 +72,7 @@ func (o *Deployment) Mutate(obj interfaces.Object) error { deploy := obj.(*appsv1.Deployment) + // TODO TO FIX merge meta o.PodSpec.ObjectMeta = o.ObjectMeta err := MutateDeployment(o, deploy) diff --git a/objects/secret/mutate.go b/objects/secret/mutate.go index 069b829..f9fb46d 100644 --- a/objects/secret/mutate.go +++ b/objects/secret/mutate.go @@ -16,6 +16,8 @@ limitations under the License. package secret import ( + "strings" + corev1 "k8s.io/api/core/v1" meta "k8s.libre.sh/meta" ) @@ -28,20 +30,28 @@ func MutateSecret(r Mutate, obj *corev1.Secret, m meta.Meta) error { data := r.GetData() + genParams := strings.Split(obj.ObjectMeta.Annotations["settings.k8s.libre.sh/generate"], ",") + + for _, p := range genParams { + delete(data, p) + } + if len(obj.Data) == 0 { obj.Data = make(map[string][]byte, len(data)) } if len(data) > 0 { for k, v := range data { - // TODO TOFIX IMPROVE SECRET GENERATION CYCLE, only generated secrets should not be updated unless asked for - if len(obj.Data[k]) == 0 { - obj.Data[k] = []byte(v) + /* // TODO TOFIX IMPROVE SECRET GENERATION CYCLE, only generated secrets should not be updated unless asked for + if len(obj.Data[k]) == 0 { + obj.Data[k] = []byte(v) - } + } */ + obj.Data[k] = []byte(v) } } + // TOD TO FIX meta.MutateMeta(m, obj) return nil diff --git a/objects/service/object.go b/objects/service/object.go index 261d2c0..dbb22eb 100644 --- a/objects/service/object.go +++ b/objects/service/object.go @@ -101,7 +101,6 @@ func (p *Port) GetServicePort() corev1.ServicePort { func (o *Service) Mutate(obj interfaces.Object) error { MutateService(o, obj.(*corev1.Service), o.ObjectMeta) meta.MutateMeta(o, obj) - // mutate.MutateMetaService(o, obj) return nil } -- GitLab From 5f858018ee18b9b26c80d47c1c4cf247f8e0ec1c Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Sun, 24 May 2020 03:05:03 +0200 Subject: [PATCH 13/18] fix sort envvars or pod gets updated --- application/settings/parameters/parameters_helpers.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/application/settings/parameters/parameters_helpers.go b/application/settings/parameters/parameters_helpers.go index 4e3a512..cac6e80 100644 --- a/application/settings/parameters/parameters_helpers.go +++ b/application/settings/parameters/parameters_helpers.go @@ -17,6 +17,7 @@ package parameters import ( "bytes" + "sort" "text/template" "github.com/presslabs/controller-util/rand" @@ -116,6 +117,11 @@ func (p *Parameters) GetEnvVar() []corev1.EnvVar { } if len(envVars) > 0 { + // Sort var to avoid update of the object if var are not in the same order? + sort.SliceStable(envVars, func(i, j int) bool { + return envVars[i].Name < envVars[j].Name + }) + return envVars } return nil -- GitLab From 427b43571708150422c4c14e36d967ee9e064eb4 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 25 May 2020 19:41:54 +0200 Subject: [PATCH 14/18] sort env & fix sort parameter by key --- application/settings/component.go | 4 +- application/settings/config.go | 42 +++++++++++++++---- application/settings/parameters/parameter.go | 2 + .../settings/parameters/parameter_helper.go | 1 - application/settings/parameters/utils.go | 12 +++--- application/settings/settings.go | 8 ++-- go.mod | 1 + 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/application/settings/component.go b/application/settings/component.go index 863e102..eefbe9b 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -106,7 +106,8 @@ func (s *Component) GetObjects() map[int]objects.Object { for _, p := range *s.ConfigSpec.Parameters { // TODO TO FIX if p.MountType == parameters.MountEnvFile && - p.Type == parameters.SecretParameter && + // TODO TO FIX + (p.Type == parameters.SecretParameter || p.Type == "") && len(p.Value) > 0 { if p.Generate != parameters.GenerateTemplate && p.Generate != "" { genSecretParams = append(genSecretParams, p.Key) @@ -195,6 +196,7 @@ func InitParametersValueFrom(s *Component, c client.Client) error { for k, v := range paramsBySecretSource { sec.SetName(k) + err := parameters.GetAndMergeParameters(v, paramsByKey, c, sec) if err != nil { return err diff --git a/application/settings/config.go b/application/settings/config.go index b5542ad..057ea8e 100644 --- a/application/settings/config.go +++ b/application/settings/config.go @@ -33,6 +33,8 @@ limitations under the License. package settings import ( + "sort" + corev1 "k8s.io/api/core/v1" "k8s.libre.sh/application/settings/parameters" ) @@ -73,7 +75,11 @@ func (c *ConfigSpec) SetSources(sources []Source) { c.Sources = sources } // GetEnvFrom returns a list of EnvFromSource to populate environment variables in the container. func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { - envFroms := []corev1.EnvFromSource{} + // envFroms := []corev1.EnvFromSource{} + envFromSecret := []corev1.EnvFromSource{} + envFromConfigMap := []corev1.EnvFromSource{} + + // envFromMap := map[int]corev1.EnvFromSource{} envFrom := corev1.EnvFromSource{} src := Source{} @@ -105,7 +111,8 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { }, }, } - envFroms = append(envFroms, envFrom) + // envFromMap[k] = envFrom + envFromConfigMap = append(envFromConfigMap, envFrom) } else if source.Type == "secret" { envFrom = corev1.EnvFromSource{ SecretRef: &corev1.SecretEnvSource{ @@ -114,16 +121,35 @@ func (c *ConfigSpec) GetEnvFrom() []corev1.EnvFromSource { }, }, } - envFroms = append(envFroms, envFrom) + // envFromMap[k] = envFrom + envFromSecret = append(envFromSecret, envFrom) } } } - if len(envFroms) > 0 { - return envFroms - } - - return nil + // We need to sort so the order is always the same and container is not update + // if len(envFromSecret) > 0 { + sort.SliceStable(envFromSecret, func(i, j int) bool { + return envFromSecret[i].SecretRef.Name < envFromSecret[j].SecretRef.Name + }) + sort.SliceStable(envFromConfigMap, func(i, j int) bool { + return envFromConfigMap[i].ConfigMapRef.Name < envFromConfigMap[j].ConfigMapRef.Name + }) + // } + + envFroms := append(envFromSecret, envFromConfigMap...) + + /* if len(envFroms) > 0 { + return envFroms + } + */ + /* for _, v := range envFromMap { + envFroms = append(envFroms, v) + } + */ + return envFroms + + // return nil } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/application/settings/parameters/parameter.go b/application/settings/parameters/parameter.go index 92cea70..8370b89 100644 --- a/application/settings/parameters/parameter.go +++ b/application/settings/parameters/parameter.go @@ -59,6 +59,8 @@ type Parameters []*Parameter type Parameter struct { // Key of the parameter, can be mounted as as an environment variable, used in template // or as in the data fied of configmap/secret + // + // Key must be unique Key string `json:"key,omitempty"` // Value of the paramater, should not contain secret values // If it is a template, ParameterType should be template diff --git a/application/settings/parameters/parameter_helper.go b/application/settings/parameters/parameter_helper.go index dbdd998..36fc17c 100644 --- a/application/settings/parameters/parameter_helper.go +++ b/application/settings/parameters/parameter_helper.go @@ -23,7 +23,6 @@ import ( // GetEnvVar gets an environment variables to set in the container. func (p *Parameter) GetEnvVar() (envVar corev1.EnvVar, err error) { - switch p.MountType { case MountLiteral: if len(p.Value) > 0 && len(p.Key) > 0 { diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index 93e46b2..d439455 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -63,17 +63,17 @@ func Marshal(i interface{}) (Parameters, error) { return parameters, nil } -// Sort parameters by keys or fromKeys if it exist +// Sort parameters by keys func ParametersByKey(p *Parameters) map[string]*Parameter { paramsByKey := map[string]*Parameter{} for _, param := range *p { - if len(param.FromKey) > 0 { + /* if len(param.FromKey) > 0 { paramsByKey[param.FromKey] = param - } else { - paramsByKey[param.Key] = param - } + } else { */ + paramsByKey[param.Key] = param + // } } return paramsByKey } @@ -128,7 +128,7 @@ func GetAndMergeParameters( if len(params) > 0 { for _, pp := range params { - paramsByKey[pp.FromKey].Value = string(data[pp.FromKey]) + paramsByKey[pp.Key].Value = string(data[pp.FromKey]) } } else { for kk, vv := range data { diff --git a/application/settings/settings.go b/application/settings/settings.go index 59437c1..e9c71e7 100644 --- a/application/settings/settings.go +++ b/application/settings/settings.go @@ -16,11 +16,7 @@ limitations under the License. package settings import ( - "k8s.libre.sh/application/settings/parameters" "k8s.libre.sh/meta" - "k8s.libre.sh/objects" - "k8s.libre.sh/objects/configmap" - "k8s.libre.sh/objects/secret" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -46,7 +42,7 @@ func NewSettings(s Settings) *Component { } } -func GetObjects(s Settings) map[int]objects.Object { +/* func GetObjects(s Settings) map[int]objects.Object { cm := &configmap.ConfigMap{ ObjectMeta: &meta.ObjectMeta{}, @@ -65,6 +61,7 @@ func GetObjects(s Settings) map[int]objects.Object { for _, p := range *params.GetParameters() { if p.MountType == parameters.MountEnvFile && + // TO FIX p.Type == parameters.SecretParameter && len(p.Value) > 0 { secret.Parameters = append(secret.Parameters, p) @@ -92,3 +89,4 @@ func GetObjects(s Settings) map[int]objects.Object { return objs } +*/ diff --git a/go.mod b/go.mod index 28fa277..528b57e 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/golangci/golangci-lint v1.27.0 // indirect + github.com/imdario/mergo v0.3.8 github.com/onsi/ginkgo v1.12.0 github.com/onsi/gomega v1.9.0 github.com/presslabs/controller-util v0.2.2 -- GitLab From 30f9026c8bc559cc5f5806aeb01bf71eb8dfddd2 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 25 May 2020 20:20:08 +0200 Subject: [PATCH 15/18] fix add sources only if resources is created --- application/settings/component.go | 11 ++++++++--- application/settings/parameters/utils.go | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/application/settings/component.go b/application/settings/component.go index eefbe9b..6e78b4e 100644 --- a/application/settings/component.go +++ b/application/settings/component.go @@ -224,9 +224,14 @@ func InitParametersValueFrom(s *Component, c client.Client) error { // s.SecretRefs = []string{s.GetSecretMeta().GetName()} // s.ConfigRefs = []string{s.GetConfigMapMeta().GetName()} - s.Sources = []Source{ - secretSrc, - configSrc, + s.Sources = []Source{} + + if len(paramsByConfigMapSource) > 0 { + s.Sources = append(s.Sources, configSrc) + } + + if len(paramsBySecretSource) > 0 { + s.Sources = append(s.Sources, secretSrc) } for _, v := range paramsByKey { diff --git a/application/settings/parameters/utils.go b/application/settings/parameters/utils.go index d439455..fde7867 100644 --- a/application/settings/parameters/utils.go +++ b/application/settings/parameters/utils.go @@ -129,6 +129,7 @@ func GetAndMergeParameters( if len(params) > 0 { for _, pp := range params { paramsByKey[pp.Key].Value = string(data[pp.FromKey]) + paramsByKey[pp.Key].Generate = "" } } else { for kk, vv := range data { -- GitLab From fae102af15ce1a97973e1c3ae9de8c8efbde2082 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 25 May 2020 20:27:48 +0200 Subject: [PATCH 16/18] fix network backend --- application/components/network.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/components/network.go b/application/components/network.go index 8f81269..e312e86 100644 --- a/application/components/network.go +++ b/application/components/network.go @@ -33,7 +33,7 @@ import ( type Network struct { IngressMeta *meta.ObjectMeta `json:"ingressMeta,omitempty"` ServiceMeta *meta.ObjectMeta `json:"serviceMeta,omitempty"` - *Backend `json:"backend,inline"` + *Backend `json:",inline"` } type Service struct { @@ -123,6 +123,8 @@ func (b *Backend) GetIngressBackendPaths() []networkingv1beta1.HTTPIngressPath { func (b *Backend) GetIngressRule() networkingv1beta1.IngressRule { + fmt.Println("yoooooooooooooo") + fmt.Println(b.Hostname) rule := networkingv1beta1.IngressRule{ Host: b.Hostname, IngressRuleValue: networkingv1beta1.IngressRuleValue{ -- GitLab From d37ee725cb164258dab31bbe49056b83b00afd04 Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 25 May 2020 22:41:19 +0200 Subject: [PATCH 17/18] cleanup --- application/components/network.go | 2 -- go.mod | 1 - go.sum | 6 ++++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/application/components/network.go b/application/components/network.go index e312e86..1c58ec1 100644 --- a/application/components/network.go +++ b/application/components/network.go @@ -123,8 +123,6 @@ func (b *Backend) GetIngressBackendPaths() []networkingv1beta1.HTTPIngressPath { func (b *Backend) GetIngressRule() networkingv1beta1.IngressRule { - fmt.Println("yoooooooooooooo") - fmt.Println(b.Hostname) rule := networkingv1beta1.IngressRule{ Host: b.Hostname, IngressRuleValue: networkingv1beta1.IngressRuleValue{ diff --git a/go.mod b/go.mod index 528b57e..28fa277 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.13 require ( github.com/golangci/golangci-lint v1.27.0 // indirect - github.com/imdario/mergo v0.3.8 github.com/onsi/ginkgo v1.12.0 github.com/onsi/gomega v1.9.0 github.com/presslabs/controller-util v0.2.2 diff --git a/go.sum b/go.sum index d0b0c39..306ccab 100644 --- a/go.sum +++ b/go.sum @@ -301,6 +301,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= @@ -349,6 +350,7 @@ github.com/nakabonne/nestif v0.3.0 h1:+yOViDGhg8ygGrmII72nV9B/zGxY188TYpfolntsaP github.com/nakabonne/nestif v0.3.0/go.mod h1:dI314BppzXjJ4HsCnbo7XzrJHPszZsjnk5wEBSYHI2c= github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E= github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= @@ -500,6 +502,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.uber.org/atomic v0.0.0-20181018215023-8dc6146f7569/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v0.0.0-20180122172545-ddea229ff1df/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= @@ -671,6 +674,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -739,6 +743,8 @@ k8s.io/utils v0.0.0-20190801114015-581e00157fb1/go.mod h1:sZAwmy6armz5eXlNoLmJcl k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6 h1:p0Ai3qVtkbCG/Af26dBmU0E1W58NID3hSSh7cMyylpM= k8s.io/utils v0.0.0-20191114200735-6ca3b61696b6/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew= +k8s.libre.sh v0.0.0-20200512221307-33a77e4357d3 h1:CaI2kDCfZEjLwKUYZFYuBVYNwKCOk8W2RbIzM81S5yM= +k8s.libre.sh v0.0.0-20200512221307-33a77e4357d3/go.mod h1:MZcprWTWk5YwauA7rnKx13F24/TSvKmfRv7p8yp9yYk= modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= -- GitLab From 43db24404455a1f210c49e611bb340192266c95c Mon Sep 17 00:00:00 2001 From: Timothee Gosselin Date: Mon, 25 May 2020 22:51:24 +0200 Subject: [PATCH 18/18] fix default container port from service --- application/components/workload.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/application/components/workload.go b/application/components/workload.go index ed54253..1ca82da 100644 --- a/application/components/workload.go +++ b/application/components/workload.go @@ -20,6 +20,8 @@ import ( meta "k8s.libre.sh/meta" "k8s.libre.sh/objects" deployment "k8s.libre.sh/objects/deployment" + + corev1 "k8s.io/api/core/v1" ) const DefaultComponent string = "app" @@ -77,6 +79,15 @@ func (w *Workload) SetDefaults() { w.Dependencies = true w.Backend.ServiceName = w.ServiceMeta.GetName() + + containerPort := corev1.ContainerPort{ + Name: w.Backend.Port.Name, + ContainerPort: w.Backend.Port.Port, + Protocol: w.Backend.Port.Protocol, + } + + w.ContainerSpec.Ports = append(w.ContainerSpec.Ports, containerPort) + } func (w *Workload) Init() { -- GitLab