Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fixes for alpha 1 release #111

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/types/applications_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions cli/pkg/tenantsinfra/tenantsinfra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/app_controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 31 additions & 8 deletions internal/khota_handler/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,48 @@ 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)
res.LogResponse()
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)

}

Expand Down
12 changes: 9 additions & 3 deletions internal/khota_handler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 0 additions & 31 deletions internal/tenant_controller/tenants_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
57 changes: 16 additions & 41 deletions internal/tenantinfra_controller/aws_eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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))
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/aws/eks/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (ec *eks) DescribeNodegroup(nodeGroupName string) (output *awseks.DescribeN
}
return nil, false, err
}

return describeNodeGroupOutput, true, nil
}

Expand Down