Răsfoiți Sursa

FE changes for custom namespaces in preview env creation

Mohammed Nafees 3 ani în urmă
părinte
comite
e028ec1ccd

+ 16 - 0
api/server/handlers/environment/update_environment_settings.go

@@ -89,6 +89,22 @@ func (c *UpdateEnvironmentSettingsHandler) ServeHTTP(w http.ResponseWriter, r *h
 		changed = true
 	}
 
+	changed = reflect.DeepEqual(env.ToEnvironmentType().NamespaceAnnotations, request.NamespaceAnnotations)
+
+	if changed {
+		if len(request.NamespaceAnnotations) > 0 {
+			var annotations []string
+
+			for k, v := range request.NamespaceAnnotations {
+				annotations = append(annotations, fmt.Sprintf("%s=%s", k, v))
+			}
+
+			env.NamespaceAnnotations = []byte(strings.Join(annotations, ","))
+		} else {
+			env.NamespaceAnnotations = []byte{}
+		}
+	}
+
 	if changed {
 		env, err = c.Repo().Environment().UpdateEnvironment(env)
 

+ 4 - 3
api/types/environment.go

@@ -146,7 +146,8 @@ type ValidatePorterYAMLResponse struct {
 }
 
 type UpdateEnvironmentSettingsRequest struct {
-	Mode               string   `json:"mode" form:"oneof=auto manual"`
-	DisableNewComments bool     `json:"disable_new_comments"`
-	GitRepoBranches    []string `json:"git_repo_branches"`
+	Mode                 string            `json:"mode" form:"oneof=auto manual"`
+	DisableNewComments   bool              `json:"disable_new_comments"`
+	GitRepoBranches      []string          `json:"git_repo_branches"`
+	NamespaceAnnotations map[string]string `json:"namespace_annotations"`
 }

+ 27 - 0
dashboard/src/main/home/cluster-dashboard/preview-environments/ConnectNewRepo.tsx

@@ -46,6 +46,9 @@ const ConnectNewRepo: React.FC = () => {
   // Disable new comments data
   const [isNewCommentsDisabled, setIsNewCommentsDisabled] = useState(false);
 
+  // Use custom namespaces
+  const [useCustomNamespaces, setUseCustomNamespaces] = useState(false);
+
   useEffect(() => {
     api
       .listEnvironments<Environment[]>(
@@ -118,6 +121,8 @@ const ConnectNewRepo: React.FC = () => {
           mode: enableAutomaticDeployments ? "auto" : "manual",
           disable_new_comments: isNewCommentsDisabled,
           git_repo_branches: selectedBranches,
+          custom_namespaces: useCustomNamespaces,
+          namespace_annotations: {},
         },
         {
           project_id: currentProject.id,
@@ -233,6 +238,28 @@ const ConnectNewRepo: React.FC = () => {
         showLoading={isLoadingBranches}
       />
 
+      <Heading>Custom namespaces</Heading>
+      <Helper>
+        By default, Porter chooses a templated namespace for every new GitHub PR.
+        When this is enabled, you can choose a custom namespace of your choice in
+        the GitHub action workflow file that we create for you.
+      </Helper>
+      <CheckboxWrapper>
+        <CheckboxRow
+          label="Use custom namespaces"
+          checked={useCustomNamespaces}
+          toggle={() => setUseCustomNamespaces(!useCustomNamespaces)}
+          wrapperStyles={{
+            disableMargin: true,
+          }}
+        />
+        <DocsHelper
+          disableMargin
+          tooltipText="When checked, it is up to you to choose a namespace for every new deployment."
+          placement="top-end"
+        />
+      </CheckboxWrapper>
+
       <ActionContainer>
         <SaveButton
           text="Add repository"

+ 1 - 0
dashboard/src/main/home/cluster-dashboard/preview-environments/environments/EnvironmentSettings.tsx

@@ -79,6 +79,7 @@ const EnvironmentSettings = () => {
           mode: deploymentMode,
           disable_new_comments: newCommentsDisabled,
           git_repo_branches: [],
+          namespace_annotations: {},
         },
         {
           project_id: currentProject.id,

+ 3 - 0
dashboard/src/shared/api.tsx

@@ -145,6 +145,8 @@ const createEnvironment = baseApi<
     mode: "auto" | "manual";
     disable_new_comments: boolean;
     git_repo_branches: string[];
+    custom_namespaces: boolean;
+    namespace_annotations: Record<string, string>;
   },
   {
     project_id: number;
@@ -169,6 +171,7 @@ const updateEnvironment = baseApi<
     mode: "auto" | "manual";
     disable_new_comments: boolean;
     git_repo_branches: string[]; // Array with branch names
+    namespace_annotations: Record<string, string>;
   },
   {
     project_id: number;