Newer
Older
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
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"
)
// 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
// A unique name identifying the instance of an application - app.kubernetes.io/instance
// The current version of the application (e.g., a semantic version, revision hash, etc.) - app.kubernetes.io/version
// The component within the architecture - app.kubernetes.io/component
// The name of a higher level application this one is part of - app.kubernetes.io/part-of
// The tool being used to manage the operation of an application - app.kubernetes.io/managed-by
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())
}
}