Explorar o código

should be namespace labels and not annotations

Mohammed Nafees %!s(int64=3) %!d(string=hai) anos
pai
achega
3299a98ee2

+ 1 - 1
api/server/handlers/cluster/create_namespace.go

@@ -55,7 +55,7 @@ func (c *CreateNamespaceHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 		return
 	}
 
-	namespace, err := agent.CreateNamespace(request.Name, request.Annotations)
+	namespace, err := agent.CreateNamespace(request.Name, request.Labels)
 
 	if err != nil {
 		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

+ 5 - 5
api/server/handlers/environment/create.go

@@ -76,14 +76,14 @@ func (c *CreateEnvironmentHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		NewCommentsDisabled: request.DisableNewComments,
 	}
 
-	if len(request.NamespaceAnnotations) > 0 {
-		var annotations []string
+	if len(request.NamespaceLabels) > 0 {
+		var labels []string
 
-		for k, v := range request.NamespaceAnnotations {
-			annotations = append(annotations, fmt.Sprintf("%s=%s", k, v))
+		for k, v := range request.NamespaceLabels {
+			labels = append(labels, fmt.Sprintf("%s=%s", k, v))
 		}
 
-		env.NamespaceAnnotations = []byte(strings.Join(annotations, ","))
+		env.NamespaceLabels = []byte(strings.Join(labels, ","))
 	}
 
 	// write Github actions files to the repo

+ 6 - 6
api/server/handlers/environment/update_environment_settings.go

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

+ 2 - 2
api/types/cluster.go

@@ -228,8 +228,8 @@ type CreateNamespaceRequest struct {
 	// example: sampleNS
 	Name string `json:"name" form:"required"`
 
-	// annotations for the kubernetes namespace, if any
-	Annotations map[string]string `json:"annotations,omitempty"`
+	// labels for the kubernetes namespace, if any
+	Labels map[string]string `json:"labels,omitempty"`
 }
 
 type GetTemporaryKubeconfigResponse struct {

+ 10 - 10
api/types/environment.go

@@ -16,15 +16,15 @@ type Environment struct {
 	DeploymentCount      uint              `json:"deployment_count"`
 	LastDeploymentStatus string            `json:"last_deployment_status"`
 	NewCommentsDisabled  bool              `json:"new_comments_disabled"`
-	NamespaceAnnotations map[string]string `json:"namespace_annotations,omitempty"`
+	NamespaceLabels      map[string]string `json:"namespace_labels,omitempty"`
 }
 
 type CreateEnvironmentRequest struct {
-	Name                 string            `json:"name" form:"required"`
-	Mode                 string            `json:"mode" form:"oneof=auto manual" default:"manual"`
-	DisableNewComments   bool              `json:"disable_new_comments"`
-	GitRepoBranches      []string          `json:"git_repo_branches"`
-	NamespaceAnnotations map[string]string `json:"namespace_annotations"`
+	Name               string            `json:"name" form:"required"`
+	Mode               string            `json:"mode" form:"oneof=auto manual" default:"manual"`
+	DisableNewComments bool              `json:"disable_new_comments"`
+	GitRepoBranches    []string          `json:"git_repo_branches"`
+	NamespaceLabels    map[string]string `json:"namespace_labels"`
 }
 
 type GitHubMetadata struct {
@@ -160,8 +160,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"`
-	NamespaceAnnotations map[string]string `json:"namespace_annotations"`
+	Mode               string            `json:"mode" form:"oneof=auto manual"`
+	DisableNewComments bool              `json:"disable_new_comments"`
+	GitRepoBranches    []string          `json:"git_repo_branches"`
+	NamespaceLabels    map[string]string `json:"namespace_labels"`
 }

+ 2 - 2
cli/cmd/apply.go

@@ -811,8 +811,8 @@ func (t *DeploymentHook) PreApply() error {
 			Name: t.namespace,
 		}
 
-		if len(deplEnv.NamespaceAnnotations) > 0 {
-			createNS.Annotations = deplEnv.NamespaceAnnotations
+		if len(deplEnv.NamespaceLabels) > 0 {
+			createNS.Labels = deplEnv.NamespaceLabels
 		}
 
 		// create the new namespace

+ 15 - 19
dashboard/src/main/home/cluster-dashboard/preview-environments/ConnectNewRepo.tsx

@@ -15,9 +15,7 @@ import PullRequestIcon from "assets/pull_request_icon.svg";
 import CheckboxRow from "components/form-components/CheckboxRow";
 import BranchFilterSelector from "./components/BranchFilterSelector";
 import Helper from "components/form-components/Helper";
-import NamespaceAnnotations, {
-  KeyValueType,
-} from "./components/NamespaceAnnotations";
+import NamespaceLabels, { KeyValueType } from "./components/NamespaceLabels";
 
 const ConnectNewRepo: React.FC = () => {
   const { currentProject, currentCluster, setCurrentError } = useContext(
@@ -49,10 +47,8 @@ const ConnectNewRepo: React.FC = () => {
   // Disable new comments data
   const [isNewCommentsDisabled, setIsNewCommentsDisabled] = useState(false);
 
-  // Namespace annotations
-  const [namespaceAnnotations, setNamespaceAnnotations] = useState<
-    KeyValueType[]
-  >([]);
+  // Namespace labels
+  const [namespaceLabels, setNamespaceLabels] = useState<KeyValueType[]>([]);
 
   useEffect(() => {
     api
@@ -117,11 +113,11 @@ const ConnectNewRepo: React.FC = () => {
 
   const addRepo = () => {
     let [owner, repoName] = repo.split("/");
-    let annotations: Record<string, string> = {};
+    let labels: Record<string, string> = {};
 
     setStatus("loading");
 
-    namespaceAnnotations
+    namespaceLabels
       .filter((elem: KeyValueType, index: number, self: KeyValueType[]) => {
         // remove any collisions that are duplicates
         let numCollisions = self.reduce((n, _elem: KeyValueType) => {
@@ -139,7 +135,7 @@ const ConnectNewRepo: React.FC = () => {
       })
       .forEach((elem: KeyValueType) => {
         if (elem.key !== "" && elem.value !== "") {
-          annotations[elem.key] = elem.value;
+          labels[elem.key] = elem.value;
         }
       });
 
@@ -151,7 +147,7 @@ const ConnectNewRepo: React.FC = () => {
           mode: enableAutomaticDeployments ? "auto" : "manual",
           disable_new_comments: isNewCommentsDisabled,
           git_repo_branches: selectedBranches,
-          namespace_annotations: annotations,
+          namespace_labels: labels,
         },
         {
           project_id: currentProject.id,
@@ -272,19 +268,19 @@ const ConnectNewRepo: React.FC = () => {
         showLoading={isLoadingBranches}
       />
 
-      <Heading>Namespace annotations</Heading>
+      <Heading>Namespace labels</Heading>
       <Helper>
-        Custom annotations to be injected into the Kubernetes namespace created
-        for each deployment.
+        Custom labels to be injected into the Kubernetes namespace created for
+        each deployment.
       </Helper>
-      <NamespaceAnnotations
-        values={namespaceAnnotations}
+      <NamespaceLabels
+        values={namespaceLabels}
         setValues={(x: KeyValueType[]) => {
-          let annotations: KeyValueType[] = [];
+          let labels: KeyValueType[] = [];
           x.forEach((entry) => {
-            annotations.push({ key: entry.key, value: entry.value });
+            labels.push({ key: entry.key, value: entry.value });
           });
-          setNamespaceAnnotations(annotations);
+          setNamespaceLabels(labels);
         }}
       />
 

+ 2 - 2
dashboard/src/main/home/cluster-dashboard/preview-environments/components/NamespaceAnnotations.tsx → dashboard/src/main/home/cluster-dashboard/preview-environments/components/NamespaceLabels.tsx

@@ -11,7 +11,7 @@ type PropsType = {
   setValues: (x: KeyValueType[]) => void;
 };
 
-const NamespaceAnnotations = ({ values, setValues }: PropsType) => {
+const NamespaceLabels = ({ values, setValues }: PropsType) => {
   useEffect(() => {
     if (!values) {
       setValues([]);
@@ -82,7 +82,7 @@ const NamespaceAnnotations = ({ values, setValues }: PropsType) => {
   );
 };
 
-export default NamespaceAnnotations;
+export default NamespaceLabels;
 
 const Spacer = styled.div`
   width: 10px;

+ 20 - 24
dashboard/src/main/home/cluster-dashboard/preview-environments/environments/EnvironmentSettings.tsx

@@ -18,9 +18,7 @@ import Banner from "components/Banner";
 import InputRow from "components/form-components/InputRow";
 import Modal from "main/home/modals/Modal";
 import { useRouting } from "shared/routing";
-import NamespaceAnnotations, {
-  KeyValueType,
-} from "../components/NamespaceAnnotations";
+import NamespaceLabels, { KeyValueType } from "../components/NamespaceLabels";
 import BranchFilterSelector from "../components/BranchFilterSelector";
 
 const EnvironmentSettings = () => {
@@ -40,9 +38,7 @@ const EnvironmentSettings = () => {
     deploymentMode,
     setDeploymentMode,
   ] = useState<EnvironmentDeploymentMode>("manual");
-  const [namespaceAnnotations, setNamespaceAnnotations] = useState<
-    KeyValueType[]
-  >([]);
+  const [namespaceLabels, setNamespaceLabels] = useState<KeyValueType[]>([]);
   const {
     environment_id: environmentId,
     repo_name: repoName,
@@ -72,17 +68,17 @@ const EnvironmentSettings = () => {
       setNewCommentsDisabled(environment.new_comments_disabled);
       setDeploymentMode(environment.mode);
 
-      if (environment.namespace_annotations) {
-        const annotations: KeyValueType[] = [];
+      if (environment.namespace_labels) {
+        const labels: KeyValueType[] = [];
 
-        Object.keys(environment.namespace_annotations).forEach((k) => {
-          annotations.push({
+        Object.keys(environment.namespace_labels).forEach((k) => {
+          labels.push({
             key: k,
-            value: environment.namespace_annotations[k],
+            value: environment.namespace_labels[k],
           });
         });
 
-        setNamespaceAnnotations(annotations);
+        setNamespaceLabels(labels);
       }
     };
 
@@ -126,11 +122,11 @@ const EnvironmentSettings = () => {
   }, [environment]);
 
   const handleSave = async () => {
-    let annotations: Record<string, string> = {};
+    let labels: Record<string, string> = {};
 
     setSaveStatus("loading");
 
-    namespaceAnnotations
+    namespaceLabels
       .filter((elem: KeyValueType, index: number, self: KeyValueType[]) => {
         // remove any collisions that are duplicates
         let numCollisions = self.reduce((n, _elem: KeyValueType) => {
@@ -148,7 +144,7 @@ const EnvironmentSettings = () => {
       })
       .forEach((elem: KeyValueType) => {
         if (elem.key !== "" && elem.value !== "") {
-          annotations[elem.key] = elem.value;
+          labels[elem.key] = elem.value;
         }
       });
 
@@ -159,7 +155,7 @@ const EnvironmentSettings = () => {
           mode: deploymentMode,
           disable_new_comments: newCommentsDisabled,
           git_repo_branches: selectedBranches,
-          namespace_annotations: annotations,
+          namespace_labels: labels,
         },
         {
           project_id: currentProject.id,
@@ -291,19 +287,19 @@ const EnvironmentSettings = () => {
           showLoading={isLoadingBranches}
         />
         <Br />
-        <Heading>Namespace annotations</Heading>
+        <Heading>Namespace labels</Heading>
         <Helper>
-          Custom annotations to be injected into the Kubernetes namespace
-          created for each deployment.
+          Custom labels to be injected into the Kubernetes namespace created for
+          each deployment.
         </Helper>
-        <NamespaceAnnotations
-          values={namespaceAnnotations}
+        <NamespaceLabels
+          values={namespaceLabels}
           setValues={(x: KeyValueType[]) => {
-            let annotations: KeyValueType[] = [];
+            let labels: KeyValueType[] = [];
             x.forEach((entry) => {
-              annotations.push({ key: entry.key, value: entry.value });
+              labels.push({ key: entry.key, value: entry.value });
             });
-            setNamespaceAnnotations(annotations);
+            setNamespaceLabels(labels);
           }}
         />
         <SavePreviewEnvironmentSettings

+ 1 - 1
dashboard/src/main/home/cluster-dashboard/preview-environments/types.ts

@@ -44,7 +44,7 @@ export type Environment = {
   last_deployment_status: DeploymentStatusUnion;
   deployment_count: number;
   mode: EnvironmentDeploymentMode;
-  namespace_annotations: Record<string, string>;
+  namespace_labels: Record<string, string>;
 };
 
 export type PullRequest = {

+ 2 - 2
dashboard/src/shared/api.tsx

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

+ 3 - 3
internal/kubernetes/agent.go

@@ -616,7 +616,7 @@ func (a *Agent) ListNamespaces() (*v1.NamespaceList, error) {
 }
 
 // CreateNamespace creates a namespace with the given name.
-func (a *Agent) CreateNamespace(name string, annotations map[string]string) (*v1.Namespace, error) {
+func (a *Agent) CreateNamespace(name string, labels map[string]string) (*v1.Namespace, error) {
 	// check if namespace exists
 	checkNS, err := a.Clientset.CoreV1().Namespaces().Get(
 		context.TODO(),
@@ -666,8 +666,8 @@ func (a *Agent) CreateNamespace(name string, annotations map[string]string) (*v1
 		},
 	}
 
-	if len(annotations) > 0 {
-		namespace.SetAnnotations(annotations)
+	if len(labels) > 0 {
+		namespace.SetLabels(labels)
 	}
 
 	return a.Clientset.CoreV1().Namespaces().Create(

+ 9 - 9
internal/models/environment.go

@@ -22,8 +22,8 @@ type Environment struct {
 	Name string
 	Mode string
 
-	NewCommentsDisabled  bool
-	NamespaceAnnotations []byte
+	NewCommentsDisabled bool
+	NamespaceLabels     []byte
 
 	// WebhookID uniquely identifies the environment when other fields (project, cluster)
 	// aren't present
@@ -59,8 +59,8 @@ func (e *Environment) ToEnvironmentType() *types.Environment {
 		GitRepoOwner:      e.GitRepoOwner,
 		GitRepoName:       e.GitRepoName,
 
-		NewCommentsDisabled:  e.NewCommentsDisabled,
-		NamespaceAnnotations: make(map[string]string),
+		NewCommentsDisabled: e.NewCommentsDisabled,
+		NamespaceLabels:     make(map[string]string),
 
 		Name: e.Name,
 		Mode: e.Mode,
@@ -74,15 +74,15 @@ func (e *Environment) ToEnvironmentType() *types.Environment {
 		env.GitRepoBranches = []string{}
 	}
 
-	if len(e.NamespaceAnnotations) > 0 {
-		env.NamespaceAnnotations = make(map[string]string)
-		annotations := string(e.NamespaceAnnotations)
+	if len(e.NamespaceLabels) > 0 {
+		env.NamespaceLabels = make(map[string]string)
+		labels := string(e.NamespaceLabels)
 
-		for _, a := range strings.Split(annotations, ",") {
+		for _, a := range strings.Split(labels, ",") {
 			k, v, found := strings.Cut(a, "=")
 
 			if found {
-				env.NamespaceAnnotations[k] = v
+				env.NamespaceLabels[k] = v
 			}
 		}
 	}