scotty.scott 2 anni fa
parent
commit
b7fa525594

+ 3 - 0
api/v1/bluegreen_types.go

@@ -48,6 +48,9 @@ type BlueGreenStatus struct {
 
 //+kubebuilder:object:root=true
 //+kubebuilder:subresource:status
+//+kubebuilder:printcolumn:name="RouteTo",type=string,JSONPath=`.status.routeTo`
+//+kubebuilder:printcolumn:name="BlueReady",type=integer,JSONPath=`.status.blueReady`
+//+kubebuilder:printcolumn:name="GreenReady",type=integer,JSONPath=`.status.greenReady`
 
 // BlueGreen is the Schema for the bluegreens API
 type BlueGreen struct {

+ 20 - 1
config/crd/bases/app.demo.kakao.com_bluegreens.yaml

@@ -15,7 +15,17 @@ spec:
     singular: bluegreen
   scope: Namespaced
   versions:
-  - name: v1
+  - additionalPrinterColumns:
+    - jsonPath: .status.routeTo
+      name: RouteTo
+      type: string
+    - jsonPath: .status.blueReady
+      name: BlueReady
+      type: integer
+    - jsonPath: .status.greenReady
+      name: GreenReady
+      type: integer
+    name: v1
     schema:
       openAPIV3Schema:
         description: BlueGreen is the Schema for the bluegreens API
@@ -13747,11 +13757,20 @@ spec:
           status:
             description: BlueGreenStatus defines the observed state of BlueGreen
             properties:
+              blueReady:
+                format: int32
+                type: integer
+              greenReady:
+                format: int32
+                type: integer
               routeTo:
                 enum:
                 - Blue
                 - Green
                 type: string
+            required:
+            - blueReady
+            - greenReady
             type: object
         type: object
     served: true

+ 4 - 2
controllers/bluegreen_controller.go

@@ -50,7 +50,6 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
 
 	bluegreen := new(v1.BlueGreen)
 	if err := r.Client.Get(ctx, req.NamespacedName, bluegreen); err != nil {
-		log.Error(err, "unable to fetch BlueGreen Resource")
 		return ctrl.Result{}, client.IgnoreNotFound(err)
 	}
 
@@ -103,7 +102,10 @@ func (r *BlueGreenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
 		}
 	}
 
-	return ctrl.Result{}, nil
+	bluegreen.Status = v1.BlueGreenStatus{
+		RouteTo: &bluegreen.Spec.RouteTo,
+	}
+	return ctrl.Result{}, r.Client.Status().Update(ctx, bluegreen)
 }
 
 // SetupWithManager sets up the controller with the Manager.