/* 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 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 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(labels) > 0 { if len(c.Labels) == 0 { c.Labels = make(map[string]string, len(labels)) } for k, v := range labels { // TODO do we need this ? why == 0 ? if len(c.Labels[k]) == 0 { c.Labels[k] = v } } } } // SetAnnotations sets the ObjectMeta annotations func (c *ObjectMeta) SetAnnotations(annotations map[string]string) { if len(annotations) > 0 { if len(c.Annotations) == 0 { c.Annotations = make(map[string]string, len(annotations)) } for k, v := range annotations { if len(c.Annotations[k]) == 0 { c.Annotations[k] = v } } } } // 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 } // SetApplication sets the ObjectMeta application name from the app.kubernetes.io/name label func (c *ObjectMeta) SetApplication(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]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 } func (c *ObjectMeta) SetInstance(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]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 } func (c *ObjectMeta) SetVersion(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]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 } func (c *ObjectMeta) SetComponent(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]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 } func (c *ObjectMeta) SetPartOf(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]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 } func (c *ObjectMeta) SetManagedBy(s string) { if len(c.Labels) == 0 { c.Labels = make(map[string]string) } c.Labels["app.kubernetes.io/managed-by"] = s }