Skip to content

Commit

Permalink
developer namespaces (#1448)
Browse files Browse the repository at this point in the history
* developer namespaces

* per review: remove unused namespaces arg
  • Loading branch information
jlmorris3827 authored Aug 7, 2021
1 parent 70a6be0 commit d79f401
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
27 changes: 26 additions & 1 deletion cloud-resource-manager/k8smgmt/appinst.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,23 @@ func WaitForAppInst(ctx context.Context, client ssh.Client, names *KubeNames, ap
for ii, _ := range objs {
for {
name = ""
namespace := DefaultNamespace
switch obj := objs[ii].(type) {
case *appsv1.Deployment:
name = obj.ObjectMeta.Name
namespace = obj.ObjectMeta.Namespace
case *appsv1.DaemonSet:
name = obj.ObjectMeta.Name
namespace = obj.ObjectMeta.Namespace
case *appsv1.StatefulSet:
name = obj.ObjectMeta.Name
namespace = obj.ObjectMeta.Namespace
}
if name == "" {
break
}
selector := fmt.Sprintf("%s=%s", MexAppLabel, name)
done, err := CheckPodsStatus(ctx, client, names.KconfEnv, DefaultNamespace, selector, waitFor, start)
done, err := CheckPodsStatus(ctx, client, names.KconfEnv, namespace, selector, waitFor, start)
if err != nil {
return err
}
Expand Down Expand Up @@ -176,6 +180,27 @@ func getConfigDirName(names *KubeNames) (string, string) {
return dir, names.AppName + names.AppOrg + names.AppVersion + ".yaml"
}

func CreateDeveloperDefinedNamespaces(ctx context.Context, client ssh.Client, names *KubeNames) error {
log.SpanLog(ctx, log.DebugLevelInfra, "CreateDeveloperDefinedNamespaces")
for _, n := range names.DeveloperDefinedNamespaces {
if n == DefaultNamespace {
continue
}
log.SpanLog(ctx, log.DebugLevelInfra, "Creating Namespace", "name", n)
cmd := fmt.Sprintf("kubectl create namespace %s --kubeconfig=%s", n, names.KconfName)
out, err := client.Output(cmd)
if err != nil {
if strings.Contains(out, "AlreadyExists") {
log.SpanLog(ctx, log.DebugLevelInfra, "namespace already exists")
} else {
log.SpanLog(ctx, log.DebugLevelInfra, "kubectl create namespace failed", "out", string(out), "err", err)
return fmt.Errorf("kubectl create namespace failed - %v", err)
}
}
}
return nil
}

func createOrUpdateAppInst(ctx context.Context, authApi cloudcommon.RegistryAuthApi, client ssh.Client, names *KubeNames, app *edgeproto.App, appInst *edgeproto.AppInst, appInstFlavor *edgeproto.Flavor, action string) error {
if action == createManifest && names.Namespace != "" {
err := CreateNamespace(ctx, client, names)
Expand Down
46 changes: 26 additions & 20 deletions cloud-resource-manager/k8smgmt/kubenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ import (
)

type KubeNames struct {
AppName string
AppVersion string
AppOrg string
HelmAppName string
AppURI string
AppImage string
AppRevision string
AppInstRevision string
ClusterName string
K8sNodeNameSuffix string
OperatorName string
ServiceNames []string
KconfName string
KconfEnv string
DeploymentType string
ImagePullSecrets []string
ImagePaths []string
IsUriIPAddr bool
Namespace string
BaseKconfName string
AppName string
AppVersion string
AppOrg string
HelmAppName string
AppURI string
AppImage string
AppRevision string
AppInstRevision string
ClusterName string
K8sNodeNameSuffix string
OperatorName string
ServiceNames []string
DeveloperDefinedNamespaces []string // namespaces included by developer in manifest
KconfName string
KconfEnv string
DeploymentType string
ImagePullSecrets []string
ImagePaths []string
IsUriIPAddr bool
Namespace string
BaseKconfName string
}

func GetKconfName(clusterInst *edgeproto.ClusterInst) string {
Expand Down Expand Up @@ -142,6 +143,11 @@ func GetKubeNames(clusterInst *edgeproto.ClusterInst, app *edgeproto.App, appIns
template = &obj.Spec.Template
case *appsv1.StatefulSet:
template = &obj.Spec.Template
case *v1.Namespace:
// if this is not a multi tenant case, any additional namespaces are from a developer manifest
if kubeNames.Namespace == "" {
kubeNames.DeveloperDefinedNamespaces = append(kubeNames.DeveloperDefinedNamespaces, obj.Name)
}
}
if template == nil {
continue
Expand Down

0 comments on commit d79f401

Please sign in to comment.