Skip to content
component.go 1.02 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
package instance

import (
	"github.com/presslabs/controller-util/syncer"
	"k8s.io/apimachinery/pkg/labels"
	interfaces "k8s.libre.sh/interfaces"
)

type Component interface {
	Meta
	SetDefaults(i Instance)
	GetObjects() map[int]Object
}

func GenComponentLabels(c Component) map[string]string {
	labels := labels.Set{
		"app.kubernetes.io/component": c.GetName(),
	}
	return labels
}

func NewSyncer(i Component, r interfaces.Reconcile, owner interfaces.Object) (syncers []syncer.Interface) {
	mutators := i.GetObjects()
	//	labels := InstanceLabels(i)

	for _, m := range mutators {
		//	m.SetLabels(labels)
		//	m.SetName(i.GetName())
		//	m.SetNamespace(i.GetNamespace())
		syncers = append(syncers, NewObjectSyncer(m, owner, r))
	}

	return syncers
}
Timothee Gosselin's avatar
Timothee Gosselin committed

func InitComponent(i Instance, c Component) {

	component := c.GetComponent()

	SetObjectMeta(i, c)
	if len(component) > 0 {
		c.SetComponent(component)
	}
	//	w.ObjectMeta.Labels["app.kubernetes.io/component"] = "app"
	for _, o := range c.GetObjects() {
		SetObjectMeta(c, o)
	}

}