forked from LaconicNetwork/kompose
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user