Selaa lähdekoodia

allow private to be missing without using default of false (#3616)

ianedwards 2 vuotta sitten
vanhempi
sitoutus
560a76abbc

+ 1 - 1
api/server/handlers/porter_app/apply.go

@@ -206,7 +206,7 @@ func addPorterSubdomainsIfNecessary(ctx context.Context, app *porterv1.PorterApp
 
 			webConfig := service.GetWebConfig()
 
-			if !webConfig.Private && len(webConfig.Domains) == 0 {
+			if !webConfig.GetPrivate() && len(webConfig.Domains) == 0 {
 				subdomain, err := porter_app.CreatePorterSubdomain(ctx, createSubdomainInput)
 				if err != nil {
 					return app, fmt.Errorf("error creating subdomain: %w", err)

+ 7 - 7
dashboard/package-lock.json

@@ -13,7 +13,7 @@
         "@loadable/component": "^5.15.2",
         "@material-ui/core": "^4.11.3",
         "@material-ui/lab": "^4.0.0-alpha.61",
-        "@porter-dev/api-contracts": "^0.1.4",
+        "@porter-dev/api-contracts": "^0.1.7",
         "@react-spring/web": "^9.6.1",
         "@sentry/react": "^6.13.2",
         "@sentry/tracing": "^6.13.2",
@@ -2455,9 +2455,9 @@
       }
     },
     "node_modules/@porter-dev/api-contracts": {
-      "version": "0.1.4",
-      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.4.tgz",
-      "integrity": "sha512-bLsjDmIxrLwZNWrPJFe7p0MC5BPVNTzwFMn8RIS4eniRIwfNWyi/MDZGq/RaWftvqEg8/G1KlI6ixCvRjoKrSg==",
+      "version": "0.1.7",
+      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.7.tgz",
+      "integrity": "sha512-S7CyV3gr0vQq+H6aUprm1nP4OKjugAATmEBQAjzhJsnZw9Gk19jPsyVciCjCKXtkzeFYyYMJR4ulybVc/pllPA==",
       "dependencies": {
         "@bufbuild/protobuf": "^1.1.0"
       }
@@ -16956,9 +16956,9 @@
       "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A=="
     },
     "@porter-dev/api-contracts": {
-      "version": "0.1.4",
-      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.4.tgz",
-      "integrity": "sha512-bLsjDmIxrLwZNWrPJFe7p0MC5BPVNTzwFMn8RIS4eniRIwfNWyi/MDZGq/RaWftvqEg8/G1KlI6ixCvRjoKrSg==",
+      "version": "0.1.7",
+      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.1.7.tgz",
+      "integrity": "sha512-S7CyV3gr0vQq+H6aUprm1nP4OKjugAATmEBQAjzhJsnZw9Gk19jPsyVciCjCKXtkzeFYyYMJR4ulybVc/pllPA==",
       "requires": {
         "@bufbuild/protobuf": "^1.1.0"
       }

+ 1 - 1
dashboard/package.json

@@ -8,7 +8,7 @@
     "@loadable/component": "^5.15.2",
     "@material-ui/core": "^4.11.3",
     "@material-ui/lab": "^4.0.0-alpha.61",
-    "@porter-dev/api-contracts": "^0.1.4",
+    "@porter-dev/api-contracts": "^0.1.7",
     "@react-spring/web": "^9.6.1",
     "@sentry/react": "^6.13.2",
     "@sentry/tracing": "^6.13.2",

+ 11 - 11
dashboard/src/lib/hooks/usePorterYaml.ts

@@ -9,17 +9,17 @@ import { z } from "zod";
 
 type PorterYamlStatus =
   | {
-    loading: true;
-    detectedName: null;
-    detectedServices: null;
-    porterYamlFound: false;
-  }
+      loading: true;
+      detectedName: null;
+      detectedServices: null;
+      porterYamlFound: false;
+    }
   | {
-    detectedServices: DetectedServices | null;
-    detectedName: string | null;
-    loading: false;
-    porterYamlFound: boolean;
-  };
+      detectedServices: DetectedServices | null;
+      detectedName: string | null;
+      loading: false;
+      porterYamlFound: boolean;
+    };
 
 /*
  *
@@ -107,7 +107,7 @@ export const usePorterYaml = ({
       try {
         const res = await api.parsePorterYaml(
           "<token>",
-          { b64_yaml: b64Yaml, app_name: appName},
+          { b64_yaml: b64Yaml, app_name: appName },
           {
             project_id: projectId,
             cluster_id: clusterId,

+ 2 - 1
dashboard/src/lib/porter-apps/index.ts

@@ -298,10 +298,11 @@ export function clientAppFromProto({
       );
 
       if (override) {
-        return deserializeService({
+        const ds = deserializeService({
           service: svc,
           override: serializeService(override),
         });
+        return ds;
       }
       return deserializeService({ service: svc });
     });

+ 31 - 31
dashboard/src/lib/porter-apps/services.ts

@@ -40,10 +40,7 @@ export const serviceValidator = z.object({
       autoscaling: autoscalingValidator.optional(),
       domains: domainsValidator,
       healthCheck: healthcheckValidator.optional(),
-      private: serviceBooleanValidator.default({
-        value: false,
-        readOnly: false,
-      }),
+      private: serviceBooleanValidator.optional(),
     }),
     z.object({
       type: z.literal("worker"),
@@ -72,27 +69,27 @@ export type SerializedService = {
   cpuCores: number;
   ramMegabytes: number;
   config:
-  | {
-    type: "web";
-    domains: {
-      name: string;
-    }[];
-    autoscaling?: SerializedAutoscaling;
-    healthCheck?: SerializedHealthcheck;
-    private: boolean;
-  }
-  | {
-    type: "worker";
-    autoscaling?: SerializedAutoscaling;
-  }
-  | {
-    type: "job";
-    allowConcurrent: boolean;
-    cron: string;
-  }
-  | {
-    type: "predeploy";
-  };
+    | {
+        type: "web";
+        domains: {
+          name: string;
+        }[];
+        autoscaling?: SerializedAutoscaling;
+        healthCheck?: SerializedHealthcheck;
+        private?: boolean;
+      }
+    | {
+        type: "worker";
+        autoscaling?: SerializedAutoscaling;
+      }
+    | {
+        type: "job";
+        allowConcurrent: boolean;
+        cron: string;
+      }
+    | {
+        type: "predeploy";
+      };
 };
 
 export function isPredeployService(service: SerializedService | ClientService) {
@@ -192,7 +189,7 @@ export function serializeService(service: ClientService): SerializedService {
           domains: config.domains.map((domain) => ({
             name: domain.name.value,
           })),
-          private: config.private.value,
+          private: config.private?.value,
         },
       })
     )
@@ -286,7 +283,9 @@ export function deserializeService({
             override: overrideWebConfig?.healthCheck,
           }),
 
-          domains: Array.from(new Set([...config.domains, ...(overrideWebConfig?.domains ?? [])])).map((domain) => ({
+          domains: Array.from(
+            new Set([...config.domains, ...(overrideWebConfig?.domains ?? [])])
+          ).map((domain) => ({
             name: ServiceField.string(
               domain.name,
               overrideWebConfig?.domains.find(
@@ -294,10 +293,11 @@ export function deserializeService({
               )?.name
             ),
           })),
-          private: ServiceField.boolean(
-            config.private,
-            overrideWebConfig?.private
-          ),
+          private:
+            typeof config.private === "boolean" ||
+            typeof overrideWebConfig?.private === "boolean"
+              ? ServiceField.boolean(config.private, overrideWebConfig?.private)
+              : undefined,
         },
       };
     })

+ 6 - 3
dashboard/src/lib/porter-apps/values.ts

@@ -64,10 +64,13 @@ export const ServiceField = {
       value: getNumericValue(defaultValue, overrideValue, validAsZero),
     };
   },
-  boolean: (defaultValue: boolean, overrideValue?: boolean): ServiceBoolean => {
+  boolean: (
+    defaultValue?: boolean,
+    overrideValue?: boolean
+  ): ServiceBoolean => {
     return {
-      readOnly: overrideValue != null,
-      value: overrideValue ?? defaultValue,
+      readOnly: typeof overrideValue === "boolean",
+      value: overrideValue ?? defaultValue ?? false,
     };
   },
 };

+ 1 - 1
dashboard/src/main/home/app-dashboard/validate-apply/services-settings/tabs/Networking.tsx

@@ -66,7 +66,7 @@ const Networking: React.FC<NetworkingProps> = ({ index, service }) => {
         render={({ field: { value, onChange } }) => (
           <Checkbox
             checked={!value}
-            disabled={service.config.private.readOnly}
+            disabled={service.config.private?.readOnly}
             toggleChecked={() => {
               onChange(!value);
             }}

+ 1 - 1
go.mod

@@ -82,7 +82,7 @@ require (
 	github.com/matryer/is v1.4.0
 	github.com/nats-io/nats.go v1.24.0
 	github.com/open-policy-agent/opa v0.44.0
-	github.com/porter-dev/api-contracts v0.1.6
+	github.com/porter-dev/api-contracts v0.1.7
 	github.com/riandyrn/otelchi v0.5.1
 	github.com/santhosh-tekuri/jsonschema/v5 v5.0.1
 	github.com/stefanmcshane/helm v0.0.0-20221213002717-88a4a2c6e77d

+ 2 - 2
go.sum

@@ -1516,8 +1516,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349/go.mod h1:wi9BfjxjF/bwiZ701TzmfKu6UKC357IOAtNr0Td0Lvw=
-github.com/porter-dev/api-contracts v0.1.6 h1:nMP/+M53Mohwe/1mNq/HYEnfIKEiDHEFItZwjLmPZ+8=
-github.com/porter-dev/api-contracts v0.1.6/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.1.7 h1:Mxua9qTur0HIhIS4gmK0a9sLcHrgJfFwSQI0CxZBkh4=
+github.com/porter-dev/api-contracts v0.1.7/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
 github.com/porter-dev/switchboard v0.0.3 h1:dBuYkiVLa5Ce7059d6qTe9a1C2XEORFEanhbtV92R+M=
 github.com/porter-dev/switchboard v0.0.3/go.mod h1:xSPzqSFMQ6OSbp42fhCi4AbGbQbsm6nRvOkrblFeXU4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=

+ 2 - 0
go.work.sum

@@ -821,6 +821,8 @@ github.com/pkg/sftp v1.10.1 h1:VasscCm72135zRysgrJDKsntdmPN+OuU3+nnHYA9wyc=
 github.com/polyfloyd/go-errorlint v0.0.0-20210722154253-910bb7978349 h1:Kq/3kL0k033ds3tyez5lFPrfQ74fNJ+OqCclRipubwA=
 github.com/porter-dev/api-contracts v0.0.63/go.mod h1:qr2L58mJLr5DUGV5OPw3REiSrQvJq6TgkKyEWP95dyU=
 github.com/porter-dev/api-contracts v0.0.86/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.1.7 h1:Mxua9qTur0HIhIS4gmK0a9sLcHrgJfFwSQI0CxZBkh4=
+github.com/porter-dev/api-contracts v0.1.7/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
 github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
 github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc=
 github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=

+ 2 - 0
internal/porter_app/parse_test.go

@@ -7,6 +7,7 @@ import (
 	"testing"
 
 	"google.golang.org/protobuf/encoding/protojson"
+	"k8s.io/utils/pointer"
 
 	porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1"
 	"github.com/sergi/go-diff/diffmatchpatch"
@@ -173,6 +174,7 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
 						Enabled:  true,
 						HttpPath: "/healthz",
 					},
+					Private: pointer.Bool(false),
 				},
 			},
 			Type: 1,

+ 3 - 1
internal/porter_app/v1/yaml.go

@@ -361,7 +361,9 @@ func webConfigProtoFromConfig(service Service) (*porterv1.WebServiceConfig, erro
 			return nil, errors.New("annotations are not supported")
 		}
 		webConfig.Domains = domains
-		webConfig.Private = !service.Config.Ingress.Enabled
+
+		private := !service.Config.Ingress.Enabled
+		webConfig.Private = &private
 	}
 
 	return webConfig, nil

+ 5 - 2
internal/porter_app/v2/yaml.go

@@ -125,7 +125,7 @@ type Service struct {
 	HealthCheck     *HealthCheck `yaml:"healthCheck,omitempty" validate:"excluded_unless=Type web"`
 	AllowConcurrent bool         `yaml:"allowConcurrent" validate:"excluded_unless=Type job"`
 	Cron            string       `yaml:"cron" validate:"excluded_unless=Type job"`
-	Private         bool         `yaml:"private" validate:"excluded_unless=Type web"`
+	Private         *bool        `yaml:"private" validate:"excluded_unless=Type web"`
 }
 
 // AutoScaling represents the autoscaling settings for web services
@@ -232,7 +232,10 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
 			})
 		}
 		webConfig.Domains = domains
-		webConfig.Private = service.Private
+
+		if service.Private != nil {
+			webConfig.Private = service.Private
+		}
 
 		serviceProto.Config = &porterv1.Service_WebConfig{
 			WebConfig: webConfig,