Skip to content
/*
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 }
/*
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,
......@@ -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)
......
/*
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,
......
/*
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,
......
/*
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,14 +20,20 @@ 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"`
*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.
......@@ -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.
......@@ -88,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 }
......@@ -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
}
/*
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,53 +24,72 @@ 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 {
// 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.
// 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"`
Strategy appsv1.DeploymentStrategy `json:"strategy,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"`
// 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
// TODO TO FIX merge meta
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
}
//func NewDeployment(spec *DeploymentSpec, p parameters.Parameters) *Deployment {
// return &Deployment{
// Parameters: p,
// DeploymentSpec: spec,
// }
//}
/*
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,
......
/*
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 (
......
/*
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 (
......
/*
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 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
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())
......
/*
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,
......@@ -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 {
......
/*
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"`
......@@ -101,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{}
......
/*
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,
......@@ -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 IMPROVE SECRET GENERATION CYCLE
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
......
/*
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,
......
/*
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 (
......
/*
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 (
......@@ -86,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
}
......
/*
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
// Uniquer returns a unique list of strings
func Unique(stringSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
......