diff --git a/api/v1/types/applications_types.go b/api/v1/types/applications_types.go index cdff494..044088b 100644 --- a/api/v1/types/applications_types.go +++ b/api/v1/types/applications_types.go @@ -10,6 +10,7 @@ const ( PendingA ApplicationPhase = "Pending" UninstallingA ApplicationPhase = "Uninstalling" Uninstalled ApplicationPhase = "Uninstalled" + RetryingA ApplicationPhase = "Retrying" DeployedA ApplicationPhase = "Deployed" InstallingA ApplicationPhase = "Installing" FailedA ApplicationPhase = "Failed" diff --git a/cli/main.go b/cli/main.go index da71dd7..10fdcf8 100755 --- a/cli/main.go +++ b/cli/main.go @@ -8,11 +8,11 @@ import ( ) func main() { - _, exists := os.LookupEnv("BAAZ_URL") - if !exists { - log.Error("Env BAAZ_URL does not exist") - os.Exit(1) - } + // _, exists := os.LookupEnv("BAAZ_URL") + // if !exists { + // log.Error("Env BAAZ_URL does not exist") + // os.Exit(1) + // } // _, exists := os.LookupEnv("BAAZ_USERNAME") // if !exists { // os.Exit(1) diff --git a/cli/pkg/tenantsinfra/tenantsinfra.go b/cli/pkg/tenantsinfra/tenantsinfra.go index 2ef3736..ce2bbcb 100644 --- a/cli/pkg/tenantsinfra/tenantsinfra.go +++ b/cli/pkg/tenantsinfra/tenantsinfra.go @@ -206,9 +206,6 @@ func CreateTenantsInfra(filePath string, dataplane string) (string, error) { return "", err } - fmt.Println(string(tiByte)) - - fmt.Println(makeTenantInfraPath(dataplane)) resp, err := http.Post( makeTenantInfraPath(dataplane), "application/json", diff --git a/internal/app_controller/deployer.go b/internal/app_controller/deployer.go index b4e6edb..fe144ae 100644 --- a/internal/app_controller/deployer.go +++ b/internal/app_controller/deployer.go @@ -46,7 +46,7 @@ func NewApplication( } func getChartName(app v1.AppSpec) string { - return fmt.Sprintf("%s-%s", app.Name, app.Namespace) + return fmt.Sprintf("%s", app.Name) } type InstallChart struct { diff --git a/internal/khota_handler/application.go b/internal/khota_handler/application.go index e3ed738..042187b 100644 --- a/internal/khota_handler/application.go +++ b/internal/khota_handler/application.go @@ -87,15 +87,15 @@ func CreateApplication(w http.ResponseWriter, req *http.Request) { } -func GetApplicationStatus(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) +func ListApplicationStatus(w http.ResponseWriter, req *http.Request) { + //vars := mux.Vars(req) - customerName := vars["customer_name"] - applicationName := vars["application_name"] + // customerName := vars["customer_name"] + // applicationName := vars["application_name"] _, dc := getKubeClientset() - application, err := dc.Resource(applicationGVK).Namespace(customerName).Get(context.TODO(), applicationName, metav1.GetOptions{}) + application, err := dc.Resource(applicationGVK).Namespace("").List(context.TODO(), metav1.ListOptions{}) if err != nil { res := NewResponse(ApplicationGetFail, internal_error, err, http.StatusInternalServerError) res.SetResponse(&w) @@ -103,9 +103,32 @@ func GetApplicationStatus(w http.ResponseWriter, req *http.Request) { return } - status, _, _ := unstructured.NestedString(application.Object, "status", "phase") - res := NewResponse("", status, nil, 200) - res.SetResponse(&w) + type listApplicationResp struct { + Name string `json:"name"` + DataplaneName string `json:"dataplane"` + TenantName string `json:"tenant"` + AppStatus map[string]interface{} `json:"status"` + } + var appResp []listApplicationResp + + for _, app := range application.Items { + + dpName, _, _ := unstructured.NestedString(app.Object, "status", "applicationCurrentSpec", "dataplane") + tenantName, _, _ := unstructured.NestedString(app.Object, "status", "applicationCurrentSpec", "tenant") + + appStatus, _, _ := unstructured.NestedMap(app.Object, "status", "appStatus") + + resp := listApplicationResp{ + Name: app.GetName(), + DataplaneName: dpName, + TenantName: tenantName, + AppStatus: appStatus, + } + + appResp = append(appResp, resp) + } + bytes, _ := json.Marshal(appResp) + sendJsonResponse(bytes, http.StatusOK, &w) } diff --git a/internal/khota_handler/routes.go b/internal/khota_handler/routes.go index c1ba491..4ddf194 100644 --- a/internal/khota_handler/routes.go +++ b/internal/khota_handler/routes.go @@ -212,11 +212,17 @@ var routes = Routes{ "/api/v1/customer/{customer_name}/tenant/{tenant_name}/application", CreateApplication, }, + // Route{ + // "GET APPLICATION STATUS", + // "GET", + // "/api/v1/customer/{customer_name}/dataplane/{dataplane_name}/application/{application_name}", + // GetApplicationStatus, + // }, Route{ - "GET APPLICATION STATUS", + "LIST APPLICATION STATUS", "GET", - "/api/v1/customer/{customer_name}/dataplane/{dataplane_name}/application/{application_name}", - GetApplicationStatus, + "/api/v1/application", + ListApplicationStatus, }, Route{ "DELETE APPLICATION", diff --git a/internal/tenant_controller/tenants_controller.go b/internal/tenant_controller/tenants_controller.go index ab77321..335632c 100644 --- a/internal/tenant_controller/tenants_controller.go +++ b/internal/tenant_controller/tenants_controller.go @@ -156,37 +156,6 @@ func (r *TenantsReconciler) reconcileDelete(ae *awsEnv) (ctrl.Result, error) { return ctrl.Result{}, err } - for ng, ngStatus := range ae.tenant.Status.NodegroupStatus { - - if ngStatus != "DELETING" { - _, err := ae.eksIC.DeleteNodeGroup(ng) - if err != nil { - return ctrl.Result{}, err - } - // update status with current nodegroup status - _, _, err = utils.PatchStatus(ae.ctx, ae.client, ae.tenant, func(obj client.Object) client.Object { - in := obj.(*v1.Tenants) - if in.Status.NodegroupStatus == nil { - in.Status.NodegroupStatus = make(map[string]string) - } - in.Status.NodegroupStatus[ng] = "DELETING" - return in - }) - if err != nil { - return ctrl.Result{}, err - } - } - - _, found, err := ae.eksIC.DescribeNodegroup(ng) - if err != nil { - return ctrl.Result{}, err - } - if found { - klog.Infof("waiting for nodegroup %s to be deleted", ng) - return ctrl.Result{RequeueAfter: time.Second * 10}, nil - } - } - // remove our finalizer from the list and update it. controllerutil.RemoveFinalizer(ae.tenant, tenantsFinalizer) klog.Infof("Deleted Tenant [%s]", ae.tenant.GetName()) diff --git a/internal/tenantinfra_controller/aws_eks.go b/internal/tenantinfra_controller/aws_eks.go index a39269b..34b610a 100644 --- a/internal/tenantinfra_controller/aws_eks.go +++ b/internal/tenantinfra_controller/aws_eks.go @@ -53,16 +53,7 @@ func getRandomSubnet(dp *v1.DataPlanes) string { } func getNodeGroupSubnet(tenants *v1.TenantsInfra, dp *v1.DataPlanes) string { - // bytebeam-medium: - // machinePool: - // - name: bytebeam-app1 - // #size: t2.small - // size: t2.medium - // new name: bytebeam-medium-bytebeam-app1-t2-medium () - // old name: bytebeam-medium-bytebeam-app1-t2-small (status) - // if len(tenants.Spec.TenantSizes) == len(tenants.Status.NodegroupStatus) { - // return "" - // } + specFlags := make(map[string]bool) for tenantName, machineSpecs := range tenants.Spec.TenantSizes { for _, machineSpec := range machineSpecs.MachineSpec { @@ -98,6 +89,7 @@ func (ae *awsEnv) ReconcileInfraTenants() error { if err != nil { return err } + if !found { nodeRole, err := ae.eksIC.CreateNodeIamRole(nodeName) if err != nil { @@ -106,7 +98,6 @@ func (ae *awsEnv) ReconcileInfraTenants() error { if nodeRole.Role == nil { return errors.New("node role is nil") } - subnet := getNodeGroupSubnet(ae.tenantsInfra, ae.dp) createNodeGroupOutput, err := ae.eksIC.CreateNodegroup(ae.getNodegroupInput(nodeName, *nodeRole.Role.Arn, subnet, &machineSpec)) @@ -176,6 +167,17 @@ func (ae *awsEnv) ReconcileInfraTenants() error { if describeNodegroupOutput != nil && describeNodegroupOutput.Nodegroup != nil && len(describeNodegroupOutput.Nodegroup.Subnets) > 0 { + + if describeNodegroupOutput.Nodegroup.ScalingConfig.MinSize != &machineSpec.Min { + // ae.eksIC.UpdateNodegroup(&awseks.UpdateNodegroupConfigInput{ + // ClusterName: describeNodegroupOutput.Nodegroup.ClusterName, + // NodegroupName: describeNodegroupOutput.Nodegroup.NodegroupName, + // ScalingConfig: &types.NodegroupScalingConfig{ + // MinSize: &machineSpec.Min, + // MaxSize: &machineSpec.Max, + // }, + // }) + } if err := ae.patchStatus(*describeNodegroupOutput.Nodegroup.NodegroupName, &v1.NodegroupStatus{ Status: string(describeNodegroupOutput.Nodegroup.Status), Subnet: describeNodegroupOutput.Nodegroup.Subnets[0], @@ -340,40 +342,13 @@ func newClientset(cluster *types.Cluster) (*kubernetes.Clientset, error) { return clientset, nil } -// func (ae *awsEnv) getNodeSpecForTenantSize(tenantConfig v1.TenantApplicationConfig) (*[]v1.MachineSpec, error) { - -// // cm := corev1.ConfigMap{} -// // if err := ae.client.Get( -// // ae.ctx, -// // k8stypes.NamespacedName{Name: "tenant-sizes", Namespace: "kube-system"}, -// // &cm, -// // ); err != nil { -// // return nil, err -// // } -// // sizeJson := cm.Data["size.json"] - -// // var tenantInfraAppSize v1.TenantInfraAppSize - -// // err := json.Unmarshal([]byte(sizeJson), &tenantInfraAppSize) - -// // if err != nil { -// // return nil, err -// // } - -// for _, size := range tenantInfraAppSize.TenantSizes { -// if size.Name == tenantConfig.Size { -// return &size.MachineSpec, nil -// } -// } - -// return nil, fmt.Errorf("no NodegroupSpec for app %s & size %s", tenantConfig.AppType, tenantConfig.Size) -// } - func (ae *awsEnv) getNodegroupInput(nodeName, roleArn, subnet string, machineSpec *v1.MachineSpec) (input *awseks.CreateNodegroupInput) { var taints = &[]types.Taint{} - taints = makeTaints(nodeName) + if machineSpec.StrictScheduling == v1.StrictSchedulingStatusEnable { + taints = makeTaints(nodeName) + } var capacityType types.CapacityTypes if machineSpec.Type == v1.MachineTypeLowPriority { diff --git a/pkg/aws/eks/system.go b/pkg/aws/eks/system.go index 961fc35..4b8653a 100644 --- a/pkg/aws/eks/system.go +++ b/pkg/aws/eks/system.go @@ -36,6 +36,7 @@ func (ec *eks) DescribeNodegroup(nodeGroupName string) (output *awseks.DescribeN } return nil, false, err } + return describeNodeGroupOutput, true, nil }