Просмотр исходного кода

Merge branch 'master' into nafees/workers

Mohammed Nafees 3 лет назад
Родитель
Сommit
6235d0be0a

+ 5 - 2
api/server/handlers/cluster/update.go

@@ -37,8 +37,9 @@ func (c *ClusterUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		return
 	}
 
-	// if the cluster has an AWS integration, make sure that the old cluster name is set
-	if cluster.AWSIntegrationID != 0 {
+	// if the cluster has an AWS integration, and the request does not have a cluster name attached, make
+	// sure that the old cluster name is set
+	if cluster.AWSIntegrationID != 0 && request.AWSClusterID == "" {
 		awsInt, err := c.Repo().AWSIntegration().ReadAWSIntegration(cluster.ProjectID, cluster.AWSIntegrationID)
 
 		if err != nil {
@@ -56,6 +57,8 @@ func (c *ClusterUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 				return
 			}
 		}
+	} else if request.AWSClusterID != "" {
+		cluster.AWSClusterID = request.AWSClusterID
 	}
 
 	cluster.Name = request.Name

+ 1 - 1
api/server/shared/commonutils/git_utils.go

@@ -39,7 +39,7 @@ func GetLatestWorkflowRun(client *github.Client, owner, repo, filename, branch s
 		return nil, err
 	}
 
-	if workflowRuns == nil || workflowRuns.GetTotalCount() == 0 {
+	if workflowRuns == nil || workflowRuns.GetTotalCount() == 0 || len(workflowRuns.WorkflowRuns) == 0 {
 		return nil, ErrNoWorkflowRuns
 	}
 

+ 5 - 0
api/types/cluster.go

@@ -29,6 +29,9 @@ type Cluster struct {
 
 	// (optional) The aws integration id, if available
 	AWSIntegrationID uint `json:"aws_integration_id"`
+
+	// (optional) The aws cluster id, if available
+	AWSClusterID string `json:"aws_cluster_id,omitempty"`
 }
 
 type ClusterCandidate struct {
@@ -260,6 +263,8 @@ type CreateClusterCandidateRequest struct {
 
 type UpdateClusterRequest struct {
 	Name string `json:"name" form:"required"`
+
+	AWSClusterID string `json:"aws_cluster_id"`
 }
 
 type ListClusterResponse []*Cluster

+ 19 - 0
dashboard/src/main/home/cluster-dashboard/dashboard/ClusterSettings.tsx

@@ -11,6 +11,9 @@ const ClusterSettings: React.FC = () => {
   const [newClusterName, setNewClusterName] = useState<string>(
     context.currentCluster.name
   );
+  const [newAWSClusterID, setNewAWSClusterID] = useState<string>(
+    context.currentCluster.aws_cluster_id
+  );
   const [successfulRename, setSuccessfulRename] = useState<boolean>(false);
 
   const [accessKeyId, setAccessKeyId] = useState<string>("");
@@ -46,6 +49,7 @@ const ClusterSettings: React.FC = () => {
         "<token>",
         {
           name: newClusterName,
+          aws_cluster_id: newAWSClusterID,
         },
         {
           project_id: context.currentProject.id,
@@ -143,6 +147,20 @@ const ClusterSettings: React.FC = () => {
     }
   }
 
+  let overrideAWSClusterNameSection =
+    context.currentCluster?.aws_integration_id &&
+    context.currentCluster?.aws_integration_id != 0 ? (
+      <InputRow
+        type="text"
+        value={newAWSClusterID}
+        setValue={(x: string) => setNewAWSClusterID(x)}
+        label="AWS Cluster ID"
+        placeholder="ex: my-awesome-cluster"
+        width="100%"
+        isRequired={false}
+      />
+    ) : null;
+
   let renameClusterSection = (
     <div>
       <Heading>Rename Cluster</Heading>
@@ -155,6 +173,7 @@ const ClusterSettings: React.FC = () => {
         width="100%"
         isRequired={true}
       />
+      {overrideAWSClusterNameSection}
       <Button color="#616FEEcc" onClick={updateClusterName}>
         Submit
       </Button>

+ 20 - 25
dashboard/src/main/home/cluster-dashboard/preview-environments/deployments/DeploymentList.tsx

@@ -100,36 +100,31 @@ const DeploymentList = () => {
 
   useEffect(() => {
     let isSubscribed = true;
-    getPRDeploymentList()
-      .then(({ data }) => {
-        if (!isSubscribed) {
-          return;
-        }
+    setIsLoading(true);
+
+    Promise.allSettled([getPRDeploymentList(), getEnvironment()]).then(
+      ([getDeploymentsResponse, getEnvironmentResponse]) => {
+        const deploymentList =
+          getDeploymentsResponse.status === "fulfilled"
+            ? getDeploymentsResponse.value.data
+            : {};
+        const environmentList =
+          getEnvironmentResponse.status === "fulfilled"
+            ? getEnvironmentResponse.value.data
+            : {};
 
-        setDeploymentList(data.deployments || []);
-        setPullRequests(data.pull_requests || []);
-      })
-      .catch((err) => {
-        console.error(err);
-        if (isSubscribed) {
-          setHasError(true);
-        }
-      });
-    getEnvironment()
-      .then(({ data }) => {
         if (!isSubscribed) {
           return;
         }
 
-        setNewCommentsDisabled(data.new_comments_disabled || false);
-      })
-      .catch((err) => {
-        console.error(err);
-        if (isSubscribed) {
-          setHasError(true);
-        }
-      });
-    setIsLoading(false);
+        setDeploymentList(deploymentList.deployments || []);
+        setPullRequests(deploymentList.pull_requrests || []);
+
+        setNewCommentsDisabled(environmentList.new_comments_disabled || false);
+
+        setIsLoading(false);
+      }
+    );
 
     return () => {
       isSubscribed = false;

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

@@ -99,6 +99,7 @@ const overwriteAWSIntegration = baseApi<
 const updateClusterName = baseApi<
   {
     name: string;
+    aws_cluster_id?: string;
   },
   {
     project_id: number;

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -8,6 +8,7 @@ export interface ClusterType {
   infra_id?: number;
   service?: string;
   aws_integration_id?: number;
+  aws_cluster_id?: string;
 }
 
 export interface DetailedClusterType extends ClusterType {

+ 9 - 1
internal/kubernetes/config.go

@@ -341,7 +341,15 @@ func (conf *OutOfClusterConfig) CreateRawConfigFromCluster() (*api.Config, error
 			return nil, err
 		}
 
-		tok, err := awsAuth.GetBearerToken(conf.getTokenCache, conf.setTokenCache, cluster.Name)
+		awsClusterID := cluster.Name
+		shouldOverride := false
+
+		if cluster.AWSClusterID != "" {
+			awsClusterID = cluster.AWSClusterID
+			shouldOverride = true
+		}
+
+		tok, err := awsAuth.GetBearerToken(conf.getTokenCache, conf.setTokenCache, awsClusterID, shouldOverride)
 
 		if err != nil {
 			return nil, err

+ 3 - 0
internal/models/cluster.go

@@ -55,6 +55,8 @@ type Cluster struct {
 
 	NotificationsDisabled bool `json:"notifications_disabled"`
 
+	AWSClusterID string
+
 	// ------------------------------------------------------------------
 	// All fields below this line are encrypted before storage
 	// ------------------------------------------------------------------
@@ -100,6 +102,7 @@ func (c *Cluster) ToClusterType() *types.Cluster {
 		Service:          serv,
 		InfraID:          c.InfraID,
 		AWSIntegrationID: c.AWSIntegrationID,
+		AWSClusterID:     c.AWSClusterID,
 	}
 }
 

+ 11 - 4
internal/models/integrations/aws.go

@@ -105,6 +105,7 @@ func (a *AWSIntegration) GetBearerToken(
 	getTokenCache GetTokenCacheFunc,
 	setTokenCache SetTokenCacheFunc,
 	clusterID string,
+	shouldClusterIdOverride bool,
 ) (string, error) {
 	cache, err := getTokenCache()
 
@@ -127,15 +128,21 @@ func (a *AWSIntegration) GetBearerToken(
 		return "", err
 	}
 
-	clusterIDGuess := string(a.AWSClusterID)
+	var validClusterId string
 
-	if clusterIDGuess == "" {
-		clusterIDGuess = clusterID
+	if shouldClusterIdOverride {
+		validClusterId = clusterID
+	} else {
+		validClusterId = string(a.AWSClusterID)
+
+		if validClusterId == "" {
+			validClusterId = clusterID
+		}
 	}
 
 	tok, err := generator.GetWithOptions(&token.GetTokenOptions{
 		Session:   sess,
-		ClusterID: clusterIDGuess,
+		ClusterID: validClusterId,
 	})
 
 	if err != nil {