瀏覽代碼

fixes for driver validation

Mohammed Nafees 3 年之前
父節點
當前提交
70a2003b31

+ 39 - 2
internal/integrations/preview/driver_validators.go

@@ -40,7 +40,11 @@ func deployDriverValidator(resource *types.Resource) error {
 	}
 
 	if source.Repo == "" {
-		source.Repo = "https://charts.getporter.dev"
+		if source.Name == "web" || source.Name == "worker" || source.Name == "job" {
+			source.Repo = "https://charts.getporter.dev"
+		} else {
+			source.Repo = "https://chart-addons.getporter.dev"
+		}
 	}
 
 	if source.Repo == "https://charts.getporter.dev" {
@@ -208,7 +212,7 @@ func pushImageDriverValidator(resource *types.Resource) error {
 }
 
 func updateConfigDriverValidator(resource *types.Resource) error {
-	_, target, err := commonValidator(resource)
+	source, target, err := commonValidator(resource)
 
 	if err != nil {
 		return err
@@ -229,6 +233,14 @@ func updateConfigDriverValidator(resource *types.Resource) error {
 		}
 	}
 
+	if source.Repo == "" {
+		if source.Name == "web" || source.Name == "worker" || source.Name == "job" {
+			source.Repo = "https://charts.getporter.dev"
+		} else {
+			source.Repo = "https://chart-addons.getporter.dev"
+		}
+	}
+
 	driverConfig := &UpdateConfigDriverConfig{}
 
 	err = mapstructure.Decode(resource.Config, driverConfig)
@@ -253,6 +265,31 @@ func updateConfigDriverValidator(resource *types.Resource) error {
 		}
 	}
 
+	if len(driverConfig.Values) > 0 && source.Repo == "https://charts.getporter.dev" {
+		if source.Name == "web" {
+			err := validateWebChartValues(driverConfig.Values)
+
+			if err != nil {
+				return fmt.Errorf("for resource '%s': error validating values for web deployment: %w",
+					resource.Name, err)
+			}
+		} else if source.Name == "worker" {
+			err := validateWorkerChartValues(driverConfig.Values)
+
+			if err != nil {
+				return fmt.Errorf("for resource '%s': error validating values for worker deployment: %w",
+					resource.Name, err)
+			}
+		} else if source.Name == "job" {
+			err := validateJobChartValues(driverConfig.Values)
+
+			if err != nil {
+				return fmt.Errorf("for resource '%s': error validating values for job deployment: %w",
+					resource.Name, err)
+			}
+		}
+	}
+
 	return nil
 }
 

+ 2 - 2
internal/integrations/preview/embed/web.values.schema.json

@@ -41,8 +41,8 @@
           "default": true
         },
         "annotations": {
-          "type": "array",
-          "items": {
+          "type": "object",
+          "additionalProperties": {
             "type": "string"
           }
         },

+ 18 - 18
internal/integrations/preview/embed/worker.values.schema.json

@@ -30,24 +30,6 @@
         }
       }
     },
-    "resources": {
-      "type": "object",
-      "properties": {
-        "requests": {
-          "type": "object",
-          "properties": {
-            "cpu": {
-              "type": "string",
-              "pattern": "^\\d+(m){0,1}$"
-            },
-            "memory": {
-              "type": "string",
-              "pattern": "^\\d+(Ki|Mi|Gi)$"
-            }
-          }
-        }
-      }
-    },
     "autoscaling": {
       "type": "object",
       "properties": {
@@ -131,6 +113,24 @@
           }
         }
       }
+    },
+    "resources": {
+      "type": "object",
+      "properties": {
+        "requests": {
+          "type": "object",
+          "properties": {
+            "cpu": {
+              "type": "string",
+              "pattern": "^\\d+(m){0,1}$"
+            },
+            "memory": {
+              "type": "string",
+              "pattern": "^\\d+(Ki|Mi|Gi)$"
+            }
+          }
+        }
+      }
     }
   }
 }

+ 1 - 1
internal/integrations/preview/utils.go

@@ -11,7 +11,7 @@ type Source struct {
 }
 
 type Target struct {
-	AppName   string
+	AppName   string `mapstructure:"app_name"`
 	Project   uint
 	Cluster   uint
 	Namespace string