forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
47 lines (43 loc) · 1.36 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package util
import (
oapi "github.com/openshift/origin/pkg/api"
projectapi "github.com/openshift/origin/pkg/project/apis/project"
kapi "k8s.io/kubernetes/pkg/apis/core"
)
// ConvertNamespace transforms a Namespace into a Project
func ConvertNamespace(namespace *kapi.Namespace) *projectapi.Project {
return &projectapi.Project{
ObjectMeta: namespace.ObjectMeta,
Spec: projectapi.ProjectSpec{
Finalizers: namespace.Spec.Finalizers,
},
Status: projectapi.ProjectStatus{
Phase: namespace.Status.Phase,
},
}
}
// convertProject transforms a Project into a Namespace
func ConvertProject(project *projectapi.Project) *kapi.Namespace {
namespace := &kapi.Namespace{
ObjectMeta: project.ObjectMeta,
Spec: kapi.NamespaceSpec{
Finalizers: project.Spec.Finalizers,
},
Status: kapi.NamespaceStatus{
Phase: project.Status.Phase,
},
}
if namespace.Annotations == nil {
namespace.Annotations = map[string]string{}
}
namespace.Annotations[oapi.OpenShiftDisplayName] = project.Annotations[oapi.OpenShiftDisplayName]
return namespace
}
// ConvertNamespaceList transforms a NamespaceList into a ProjectList
func ConvertNamespaceList(namespaceList *kapi.NamespaceList) *projectapi.ProjectList {
projects := &projectapi.ProjectList{}
for _, n := range namespaceList.Items {
projects.Items = append(projects.Items, *ConvertNamespace(&n))
}
return projects
}