Skip to content
object.go 2.68 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

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

// +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) {
	if len(c.Labels) == 0 {
		c.Labels = make(map[string]string)
	}
	if len(labels) > 0 {
		for k, v := range labels {
			if len(c.Labels[k]) == 0 {
				c.Labels[k] = v
			}
		}
	}
}

func (c *ObjectMeta) GetLabels() map[string]string { return c.Labels }

Timothee Gosselin's avatar
Timothee Gosselin committed
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 }

func (o *ObjectMeta) GetNamespace() string { return o.Namespace }

func (o *ObjectMeta) SetNamespace(namespace string) { o.Namespace = namespace }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (c *ObjectMeta) GetApplication() string { return c.Labels["app.kubernetes.io/name"] }

func (c *ObjectMeta) SetApplication(s string) { c.Labels["app.kubernetes.io/name"] = s }

func (c *ObjectMeta) GetInstance() string { return c.Labels["app.kubernetes.io/instance"] }

func (c *ObjectMeta) SetInstance(s string) { c.Labels["app.kubernetes.io/instance"] = s }

func (c *ObjectMeta) GetVersion() string { return c.Labels["app.kubernetes.io/version"] }

func (c *ObjectMeta) SetVersion(s string) { c.Labels["app.kubernetes.io/version"] = s }

func (c *ObjectMeta) GetComponent() string { return c.Labels["app.kubernetes.io/component"] }

func (c *ObjectMeta) SetComponent(s string) { c.Labels["app.kubernetes.io/component"] = s }

func (c *ObjectMeta) GetPartOf() string { return c.Labels["app.kubernetes.io/part-of"] }

func (c *ObjectMeta) SetPartOf(s string) { c.Labels["app.kubernetes.io/part-of"] = s }

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 }