Skip to content
Snippets Groups Projects
Commit 638f7d6b authored by Alka Nixon's avatar Alka Nixon
Browse files

Added feature to create new application group and swm app.

parent 64f616ce
No related branches found
No related tags found
2 merge requests!4Rht integration 2,!3Rht integration merge
......@@ -9,6 +9,7 @@ rules:
resources:
- applications
- channels
- applicationgroups
verbs:
- create
- delete
......
......@@ -5,7 +5,7 @@ metadata:
spec:
appEnergyLimit: "20" # Maximum desired level of energy expenditure for the overall k8s infrastructure associated with an application (percent)
appFailureTolerance: "" # Desired tolerance to infrastructure failures, High/Medium/Low
appName: "NewApp"
appName: "acm-swm-app"
codecoapp-msspec:
- serviceName: "database"
podspec:
......@@ -39,7 +39,7 @@ spec:
maxDelay: "1"
sendInterval: "10"
otherService:
appName: ""
appName: "acm-swm-app"
port: 0
serviceName: "front-end"
- serviceName: "front-end"
......@@ -62,7 +62,7 @@ spec:
maxDelay: "1"
sendInterval: "10"
otherService:
appName: "NewApp"
appName: "acm-swm-app"
port: 0
serviceName: "database"
complianceClass: "High" #expected level of compliance, based on a scale - High, Medium, Low
......
......@@ -18,13 +18,14 @@ package controllers
import (
"context"
"encoding/json"
// "encoding/json"
"fmt"
dc "github.com/fluidtruck/deepcopy"
"github.com/tidwall/pretty"
// "github.com/tidwall/pretty"
codecov1alpha1 "gitlab.eclipse.org/eclipse-research-labs/codeco-project/acm/api/v1alpha1"
swmv1alpha1 "gitlab.eclipse.org/rcarrollred/qos-scheduler/scheduler/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
......@@ -58,7 +59,21 @@ func (r *CodecoAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
codecoAppCR := &codecov1alpha1.CodecoApp{}
qos_scheduler_app := &swmv1alpha1.Application{}
qos_scheduler_new_app := &swmv1alpha1.Application{}
qos_scheduler_new_app := &swmv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "acm-swm-app",
Namespace: "default",
Labels: map[string]string{
"application-group": "acm-applicationgroup",
},
},
}
qos_scheduler_new_application_group := &swmv1alpha1.ApplicationGroup{
ObjectMeta: metav1.ObjectMeta{
Name: "acm-applicationgroup",
Namespace: "default",
},
}
qos_scheduler_app_list := &swmv1alpha1.ApplicationList{}
qos_scheduler_app2 := &swmv1alpha1.Application{}
......@@ -114,36 +129,49 @@ func (r *CodecoAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}*/
// TODO
// 1. Map Codeco App to SWM App (locally)
fmt.Println(time.Now().Format(time.UnixDate), " ------------------- CREATING SWM APPLICATION GROUP ------------------------- ")
qos_scheduler_new_application_group.Spec = swmv1alpha1.ApplicationGroupSpec{}
err := r.Get(ctx, client.ObjectKey{Namespace: "default", Name: "acm-applicationgroup"}, qos_scheduler_new_application_group)
if err != nil {
if errors.IsNotFound(err) {
fmt.Println("Creating new SWM application group")
if err := r.Create(ctx, qos_scheduler_new_application_group); err != nil {
fmt.Println("Error creating SWM application group")
return ctrl.Result{}, err
}
} else {
return ctrl.Result{}, err
}
} else {
fmt.Println("SWM application group already exists")
}
fmt.Println(time.Now().Format(time.UnixDate), " ------------------- CREATING SWM APP ------------------------- ")
qos_scheduler_new_app.Name = "acm-swm-app"
qos_scheduler_new_app.Namespace = "default"
qos_scheduler_new_app.Spec = swmv1alpha1.ApplicationSpec{}
qos_scheduler_new_app.Spec.Workloads = []swmv1alpha1.ApplicationWorkloadSpec{}
/// -------------------- UPDATE SWM Application --------------------------------------
fmt.Println(time.Now().Format(time.UnixDate), " ------------------- CREATING SWM APP ------------------------- ")
// Map from Codeco Application Model to SWM Application Model
MapToSWMApplicationModel(codecoAppCR, qos_scheduler_new_app)
err := r.Get(ctx, client.ObjectKey{Namespace: "default", Name: "acm-swm-app"}, qos_scheduler_new_app)
err = r.Get(ctx, client.ObjectKey{Namespace: "default", Name: "acm-swm-app"}, qos_scheduler_new_app)
if err != nil {
fmt.Println("Creating new SWM app")
if err := r.Create(ctx, qos_scheduler_new_app); err != nil {
fmt.Println("Error creating SWM")
return ctrl.Result{}, err
}
return ctrl.Result{}, err
}
// Map from Codeco Apllication Model to SWM Application Model
MapToSWMApplicationModel(codecoAppCR, qos_scheduler_new_app)
} else {
// Update SWM Application if already exists
fmt.Println("Already exists: Updating SWM app")
err = r.Update(ctx, qos_scheduler_new_app)
fmt.Println("Updating SWM app")
err = r.Update(ctx, qos_scheduler_new_app)
if err != nil {
fmt.Print("Error updating swm")
return ctrl.Result{}, err
if err != nil {
fmt.Print("Error updating swm")
return ctrl.Result{}, err
}
}
// WAIT 8secs just to ensure UPDATE has completed
......@@ -159,16 +187,14 @@ func (r *CodecoAppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}
fmt.Print("\n\n", qos_scheduler_new_app)
json_SWM, _ := json.Marshal(qos_scheduler_new_app)
fmt.Println("\n\nNew SWM app JSON:\n", string(pretty.Pretty(json_SWM)))
// fmt.Print("\n\n", qos_scheduler_new_app)
// json_SWM, _ := json.Marshal(qos_scheduler_new_app)
// fmt.Println("\n\nNew SWM app JSON:\n", string(pretty.Pretty(json_SWM)))
fmt.Println(time.Now().Format(time.UnixDate), "SWM App :", qos_scheduler_app2.Name)
fmt.Println(time.Now().Format(time.UnixDate), "SWM App Phase3 :", qos_scheduler_app2.Status.Phase)
fmt.Println(time.Now().Format(time.UnixDate), "SWM App W1 Basename:", qos_scheduler_app2.Spec.Workloads[0].Basename)
// TODO(user): your logic here
//if codecoAppCR.Status.Status == "" {
// codecoAppCR.Status.Status = codecov1alpha1.OK
//} else {
......@@ -190,8 +216,8 @@ func CreateNewSWMApplicationModel() {
}
// Function to Map from Codeco Apllication Model to SWM Application Model
func MapToSWMApplicationModel(codecoApp *codecov1alpha1.CodecoApp, swmApp *swmv1alpha1.Application) {
//Function to Map from Codeco Apllication Model to SWM Application Model
dc.DeepCopy(codecoApp.Spec, &swmApp.Spec)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment