From dd9e601aad3ee9ac88a985dc8f340d10f0abb968 Mon Sep 17 00:00:00 2001
From: Josh Salomon <jsalomon@redhat.com>
Date: Thu, 26 Oct 2023 12:25:37 +0300
Subject: [PATCH] Some application model chnages for D11

Signed-off-by: Josh Salomon <jsalomon@redhat.com>
---
 api/v1alpha1/codecoapp_types.go               | 38 ++++++++++++++++
 api/v1alpha1/zz_generated.deepcopy.go         | 38 +++++++++++++++-
 .../bases/codeco.he-codeco.eu_codecoapps.yaml | 43 +++++++++++++++++++
 config/manager/kustomization.yaml             |  2 +-
 config/samples/codeco_v1alpha1_codecoapp.yaml | 21 ++++++++-
 5 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/api/v1alpha1/codecoapp_types.go b/api/v1alpha1/codecoapp_types.go
index cc9bc51..50afdbe 100644
--- a/api/v1alpha1/codecoapp_types.go
+++ b/api/v1alpha1/codecoapp_types.go
@@ -47,6 +47,40 @@ const (
 // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
 // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
 
+// CodecoAppResource defines the resource consumption of CodecoApp
+type CodecoAppResource struct {
+	//+kubebuilder:validation:Minimum=0
+	//+kubebuilder:validation:default=100
+	CpuUsagePct uint64 `json:"cpu-usage-pct,omitempty"`
+
+	//+kubebuilder:validation:Minimum=0
+	//+kubebuilder:validation:default=8
+	MemUsageGB uint64 `json:"mem-usage-GB,omitempty"`
+
+	//+kubebuilder:validation:Minimum=0
+	//+kubebuilder:validation:default=25
+	NWBandwidthMbs uint64 `json:"nwbandwidth-Mbs,omitempty"`
+
+	//+kubebuilder:validation:Minimum=0
+	//+kubebuilder:validation:default=10
+	NWLatencyMs uint64 `json:"nwlatency-ms,omitempty"`
+}
+
+// CodecoAppMSSpec defines the desired state of CodecoApp micro service
+type CodecoAppMSSpec struct {
+	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
+	// Important: Run "make" to regenerate code after modifying this file
+
+	// Name is an used to identify the CODECO micro service. Edit codecoapp_types.go to remove/update
+	Name string `json:"name"`
+
+	// A reference to the PodSpec of the microservice. Edit codecoapp_types.go to remove/update
+	PodSpecName string `json:"podspecname"`
+
+	// RequiredResources is used to identify the CODECO micro service required resources. Edit codecoapp_types.go to remove/update
+	RequiredResources CodecoAppResource `json:"required-resources,omitempty"`
+}
+
 // CodecoAppSpec defines the desired state of CodecoApp
 type CodecoAppSpec struct {
 	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
@@ -60,6 +94,10 @@ type CodecoAppSpec struct {
 	// QosClass is used to identify the CODECO application QoS. Edit codecoapp_types.go to remove/update
 	QosClass CodecoQosClass `json:"qosclass,omitempty"`
 
+	//+kubebuilder:validation:MinItems=1
+	// MCSpecs is used to identify the CODECO micro services which compose the application. Edit codecoapp_types.go to remove/update
+	MCSpecs []CodecoAppMSSpec `json:"codecoapp-msspec,omitempty"`
+
 	//+kubebuilder:validation:Enum=Gold;Silver;BestEffort
 
 	// SecurityClass is used to identify the CODECO application security class. Edit codecoapp_types.go to remove/update
diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go
index 4ec708b..414bd56 100644
--- a/api/v1alpha1/zz_generated.deepcopy.go
+++ b/api/v1alpha1/zz_generated.deepcopy.go
@@ -30,7 +30,7 @@ func (in *CodecoApp) DeepCopyInto(out *CodecoApp) {
 	*out = *in
 	out.TypeMeta = in.TypeMeta
 	in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
-	out.Spec = in.Spec
+	in.Spec.DeepCopyInto(&out.Spec)
 	out.Status = in.Status
 }
 
@@ -84,9 +84,45 @@ func (in *CodecoAppList) DeepCopyObject() runtime.Object {
 	return nil
 }
 
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CodecoAppMSSpec) DeepCopyInto(out *CodecoAppMSSpec) {
+	*out = *in
+	out.RequiredResources = in.RequiredResources
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodecoAppMSSpec.
+func (in *CodecoAppMSSpec) DeepCopy() *CodecoAppMSSpec {
+	if in == nil {
+		return nil
+	}
+	out := new(CodecoAppMSSpec)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CodecoAppResource) DeepCopyInto(out *CodecoAppResource) {
+	*out = *in
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodecoAppResource.
+func (in *CodecoAppResource) DeepCopy() *CodecoAppResource {
+	if in == nil {
+		return nil
+	}
+	out := new(CodecoAppResource)
+	in.DeepCopyInto(out)
+	return out
+}
+
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *CodecoAppSpec) DeepCopyInto(out *CodecoAppSpec) {
 	*out = *in
+	if in.MCSpecs != nil {
+		in, out := &in.MCSpecs, &out.MCSpecs
+		*out = make([]CodecoAppMSSpec, len(*in))
+		copy(*out, *in)
+	}
 }
 
 // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CodecoAppSpec.
diff --git a/config/crd/bases/codeco.he-codeco.eu_codecoapps.yaml b/config/crd/bases/codeco.he-codeco.eu_codecoapps.yaml
index 6e20c67..0cbe415 100644
--- a/config/crd/bases/codeco.he-codeco.eu_codecoapps.yaml
+++ b/config/crd/bases/codeco.he-codeco.eu_codecoapps.yaml
@@ -35,6 +35,49 @@ spec:
           spec:
             description: CodecoAppSpec defines the desired state of CodecoApp
             properties:
+              codecoapp-msspec:
+                description: MCSpecs is used to identify the CODECO micro services
+                  which compose the application. Edit codecoapp_types.go to remove/update
+                items:
+                  description: CodecoAppMSSpec defines the desired state of CodecoApp
+                    micro service
+                  properties:
+                    name:
+                      description: Name is an used to identify the CODECO micro service.
+                        Edit codecoapp_types.go to remove/update
+                      type: string
+                    podspecname:
+                      description: A reference to the PodSpec of the microservice.
+                        Edit codecoapp_types.go to remove/update
+                      type: string
+                    required-resources:
+                      description: RequiredResources is used to identify the CODECO
+                        micro service required resources. Edit codecoapp_types.go
+                        to remove/update
+                      properties:
+                        cpu-usage-pct:
+                          format: int64
+                          minimum: 0
+                          type: integer
+                        mem-usage-GB:
+                          format: int64
+                          minimum: 0
+                          type: integer
+                        nwbandwidth-Mbs:
+                          format: int64
+                          minimum: 0
+                          type: integer
+                        nwlatency-ms:
+                          format: int64
+                          minimum: 0
+                          type: integer
+                      type: object
+                  required:
+                  - name
+                  - podspecname
+                  type: object
+                minItems: 1
+                type: array
               name:
                 description: Name is an used to identify the CODECO application. Edit
                   codecoapp_types.go to remove/update
diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml
index 9d70969..6beebd8 100644
--- a/config/manager/kustomization.yaml
+++ b/config/manager/kustomization.yaml
@@ -5,4 +5,4 @@ kind: Kustomization
 images:
 - name: controller
   newName: quay.io/jsalomon/codecoapp-test
-  newTag: v0.0.2
+  newTag: v0.0.4
diff --git a/config/samples/codeco_v1alpha1_codecoapp.yaml b/config/samples/codeco_v1alpha1_codecoapp.yaml
index aa6e7e0..18f2b49 100644
--- a/config/samples/codeco_v1alpha1_codecoapp.yaml
+++ b/config/samples/codeco_v1alpha1_codecoapp.yaml
@@ -11,5 +11,24 @@ metadata:
 spec:
   name: My CODECO App
   qosclass: Dev
-  
+  codecoapp-msspec: [
+    {
+      name: "CODECO micro service 1",
+      podspecname: "MicroService1",
+      required-resources: {
+        cpu-usage-pct: 200,
+        mem-usage-GB: 120,
+        nwbandwidth-Mbs: 10
+      }
+    },
+    {
+      name: "CODECO micro service 2",
+      podspecname: "MicroService2",
+      required-resources: {
+        cpu-usage-pct: 150,
+        mem-usage-GB: 80,
+        nwbandwidth-Mbs: 20
+      }
+    },
+  ]  
   # TODO(user): Add fields here
-- 
GitLab