Feat add ns generation (#1667)

* feat: add ns generation for k8s

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>

* feat: add ns generation for openshift

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>

* test: add functional tests

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>

* fix: remove some code nits

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>

---------

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
AhmedGrati
2023-07-16 22:59:16 +01:00
committed by GitHub
parent 071451dfdf
commit b6b708b637
14 changed files with 291 additions and 1 deletions
+32
View File
@@ -31,6 +31,8 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// Selector used as labels and selector
@@ -443,3 +445,33 @@ func PushDockerImageWithOpt(service kobject.ServiceConfig, serviceName string, o
return nil
}
// CreateNamespace creates a Kubernetes namespace, which can be used in both:
// Openshift and Kubernetes
func CreateNamespace(namespace string) *api.Namespace {
return &api.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
},
}
}
// AssignNamespaceToObjects will add the namespace metadata to each object
func AssignNamespaceToObjects(objs *[]runtime.Object, namespace string) {
ns := "default"
if namespace != "" {
ns = namespace
}
var result []runtime.Object
for _, obj := range *objs {
if us, ok := obj.(metav1.Object); ok {
us.SetNamespace(ns)
}
result = append(result, obj)
}
*objs = result
}