Procházet zdrojové kódy

deprecate instances and support instancesOptional (#3870)

Feroze Mohideen před 2 roky
rodič
revize
954a0d3ab2

+ 13 - 9
dashboard/package-lock.json

@@ -13,7 +13,6 @@
         "@loadable/component": "^5.15.2",
         "@material-ui/core": "^4.11.3",
         "@material-ui/lab": "^4.0.0-alpha.61",
-        "@porter-dev/api-contracts": "^0.2.23",
         "@react-spring/web": "^9.6.1",
         "@sentry/react": "^6.13.2",
         "@sentry/tracing": "^6.13.2",
@@ -90,6 +89,7 @@
         "@babel/preset-react": "^7.14.5",
         "@babel/preset-typescript": "^7.15.0",
         "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
+        "@porter-dev/api-contracts": "^0.2.27",
         "@testing-library/jest-dom": "^4.2.4",
         "@testing-library/react": "^9.3.2",
         "@testing-library/user-event": "^7.1.2",
@@ -1957,7 +1957,8 @@
     "node_modules/@bufbuild/protobuf": {
       "version": "1.3.3",
       "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-1.3.3.tgz",
-      "integrity": "sha512-AoHSiIpTFF97SQgmQni4c+Tyr0CDhkaRaR2qGEJTEbauqQwLRpLrd9yVv//wVHOSxr/b4FJcL54VchhY6710xA=="
+      "integrity": "sha512-AoHSiIpTFF97SQgmQni4c+Tyr0CDhkaRaR2qGEJTEbauqQwLRpLrd9yVv//wVHOSxr/b4FJcL54VchhY6710xA==",
+      "dev": true
     },
     "node_modules/@discoveryjs/json-ext": {
       "version": "0.5.7",
@@ -2457,9 +2458,10 @@
       }
     },
     "node_modules/@porter-dev/api-contracts": {
-      "version": "0.2.23",
-      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.23.tgz",
-      "integrity": "sha512-f2JTEx32fso2dg3/ADgiSRO169jsVfHc3bHG5amFJjU0z9HzxZIEEkSX0wagPTQePiVMRuTGVRAhYG1PpSsaHQ==",
+      "version": "0.2.27",
+      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.27.tgz",
+      "integrity": "sha512-Zh8R4p+gPGYXeELP5rlUbkDLf0w7wgUPWeUHniKK7WyCQNIb4zrSImVl3PC1S12eUbRfT+Nry6Jj0VcktMN0Tw==",
+      "dev": true,
       "dependencies": {
         "@bufbuild/protobuf": "^1.1.0"
       }
@@ -16630,7 +16632,8 @@
     "@bufbuild/protobuf": {
       "version": "1.3.3",
       "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-1.3.3.tgz",
-      "integrity": "sha512-AoHSiIpTFF97SQgmQni4c+Tyr0CDhkaRaR2qGEJTEbauqQwLRpLrd9yVv//wVHOSxr/b4FJcL54VchhY6710xA=="
+      "integrity": "sha512-AoHSiIpTFF97SQgmQni4c+Tyr0CDhkaRaR2qGEJTEbauqQwLRpLrd9yVv//wVHOSxr/b4FJcL54VchhY6710xA==",
+      "dev": true
     },
     "@discoveryjs/json-ext": {
       "version": "0.5.7",
@@ -16976,9 +16979,10 @@
       "integrity": "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A=="
     },
     "@porter-dev/api-contracts": {
-      "version": "0.2.23",
-      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.23.tgz",
-      "integrity": "sha512-f2JTEx32fso2dg3/ADgiSRO169jsVfHc3bHG5amFJjU0z9HzxZIEEkSX0wagPTQePiVMRuTGVRAhYG1PpSsaHQ==",
+      "version": "0.2.27",
+      "resolved": "https://registry.npmjs.org/@porter-dev/api-contracts/-/api-contracts-0.2.27.tgz",
+      "integrity": "sha512-Zh8R4p+gPGYXeELP5rlUbkDLf0w7wgUPWeUHniKK7WyCQNIb4zrSImVl3PC1S12eUbRfT+Nry6Jj0VcktMN0Tw==",
+      "dev": true,
       "requires": {
         "@bufbuild/protobuf": "^1.1.0"
       }

+ 1 - 1
dashboard/package.json

@@ -8,7 +8,6 @@
     "@loadable/component": "^5.15.2",
     "@material-ui/core": "^4.11.3",
     "@material-ui/lab": "^4.0.0-alpha.61",
-    "@porter-dev/api-contracts": "^0.2.23",
     "@react-spring/web": "^9.6.1",
     "@sentry/react": "^6.13.2",
     "@sentry/tracing": "^6.13.2",
@@ -95,6 +94,7 @@
     "@babel/preset-react": "^7.14.5",
     "@babel/preset-typescript": "^7.15.0",
     "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
+    "@porter-dev/api-contracts": "^0.2.27",
     "@testing-library/jest-dom": "^4.2.4",
     "@testing-library/react": "^9.3.2",
     "@testing-library/user-event": "^7.1.2",

+ 3 - 3
dashboard/src/lib/hooks/useAppStatus.ts

@@ -157,18 +157,18 @@ export const useAppStatus = (
 
             if (replicaSet.some((r) => r.crashLoopReason !== "") || replicaSet.some((r) => r.isFailing)) {
                 status = "failing";
-                message = `${replicaSet.length} replica${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
+                message = `${replicaSet.length} instance${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
                     } failing to run Version ${version}`;
             } else if (
                 // last check ensures that we don't say 'spinning down' unless there exists a version status above it
                 i > 0 && replicaSetArray[i - 1].every(p => !p.isFailing) && revisionIdToNumber[replicaSetArray[i - 1][0].revisionId] != null
             ) {
                 status = "spinningDown";
-                message = `${replicaSet.length} replica${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
+                message = `${replicaSet.length} instance${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
                     } still running at Version ${version}. Attempting to spin down...`;
             } else {
                 status = "running";
-                message = `${replicaSet.length} replica${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
+                message = `${replicaSet.length} instance${replicaSet.length === 1 ? "" : "s"} ${replicaSet.length === 1 ? "is" : "are"
                     } running at Version ${version}`;
             }
 

+ 8 - 0
dashboard/src/lib/porter-apps/services.ts

@@ -494,6 +494,7 @@ export function serviceProto(service: SerializedService): Service {
         new Service({
           ...service,
           runOptional: service.run,
+          instancesOptional: service.instances,
           type: serviceTypeEnumProto(config.type),
           config: {
             value: {
@@ -509,6 +510,7 @@ export function serviceProto(service: SerializedService): Service {
         new Service({
           ...service,
           runOptional: service.run,
+          instancesOptional: service.instances,
           type: serviceTypeEnumProto(config.type),
           config: {
             value: {
@@ -524,6 +526,7 @@ export function serviceProto(service: SerializedService): Service {
         new Service({
           ...service,
           runOptional: service.run,
+          instancesOptional: service.instances,
           type: serviceTypeEnumProto(config.type),
           config: {
             value: {
@@ -541,6 +544,7 @@ export function serviceProto(service: SerializedService): Service {
         new Service({
           ...service,
           runOptional: service.run,
+          instancesOptional: service.instances,
           type: serviceTypeEnumProto(config.type),
           config: {
             value: {},
@@ -569,6 +573,7 @@ export function serializedServiceFromProto({
     .with({ case: "webConfig" }, ({ value }) => ({
       ...service,
       run: service.runOptional ?? service.run,
+      instances: service.instancesOptional ?? service.instances,
       config: {
         type: "web" as const,
         autoscaling: value.autoscaling ? value.autoscaling : undefined,
@@ -579,6 +584,7 @@ export function serializedServiceFromProto({
     .with({ case: "workerConfig" }, ({ value }) => ({
       ...service,
       run: service.runOptional ?? service.run,
+      instances: service.instancesOptional ?? service.instances,
       config: {
         type: "worker" as const,
         autoscaling: value.autoscaling ? value.autoscaling : undefined,
@@ -590,6 +596,7 @@ export function serializedServiceFromProto({
         ? {
           ...service,
           run: service.runOptional ?? service.run,
+          instances: service.instancesOptional ?? service.instances,
           config: {
             type: "predeploy" as const,
           },
@@ -597,6 +604,7 @@ export function serializedServiceFromProto({
         : {
           ...service,
           run: service.runOptional ?? service.run,
+          instances: service.instancesOptional ?? service.instances,
           config: {
             type: "job" as const,
             ...value,

+ 0 - 1
dashboard/src/main/home/app-dashboard/validate-apply/services-settings/ServiceStatusFooter.tsx

@@ -5,7 +5,6 @@ import Text from "components/porter/Text";
 import Container from "components/porter/Container";
 import Button from "components/porter/Button";
 
-import { RouteComponentProps } from "react-router";
 import AnimateHeight, { Height } from "react-animate-height";
 import _ from "lodash";
 import Link from "components/porter/Link";

+ 1 - 1
go.mod

@@ -83,7 +83,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.2.24
+	github.com/porter-dev/api-contracts v0.2.27
 	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

@@ -1520,8 +1520,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.2.24 h1:0Jas/m7l+FD+1VRGYg8lq6vxTZ77A79X4A1wZcTVrEI=
-github.com/porter-dev/api-contracts v0.2.24/go.mod h1:fX6JmP5QuzxDLvqP3evFOTXjI4dHxsG0+VKNTjImZU8=
+github.com/porter-dev/api-contracts v0.2.27 h1:NZTWmbiqQF082Kl0vUtXev5gcI8lTY6bofjS4Sjwej4=
+github.com/porter-dev/api-contracts v0.2.27/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=

+ 14 - 17
internal/porter_app/test/parse_test.go

@@ -51,7 +51,6 @@ var result_nobuild = &porterv1.PorterApp{
 		"example-web": {
 			Name:         "example-web",
 			RunOptional:  pointer.String("node index.js"),
-			Instances:    0,
 			Port:         8080,
 			CpuCores:     0.1,
 			RamMegabytes: 256,
@@ -81,13 +80,13 @@ var result_nobuild = &porterv1.PorterApp{
 			Type: 1,
 		},
 		"example-wkr": {
-			Name:           "example-wkr",
-			RunOptional:    pointer.String("echo 'work'"),
-			Instances:      1,
-			Port:           80,
-			CpuCores:       0.1,
-			RamMegabytes:   256,
-			GpuCoresNvidia: 0,
+			Name:              "example-wkr",
+			RunOptional:       pointer.String("echo 'work'"),
+			InstancesOptional: pointer.Int32(1),
+			Port:              80,
+			CpuCores:          0.1,
+			RamMegabytes:      256,
+			GpuCoresNvidia:    0,
 			Config: &porterv1.Service_WorkerConfig{
 				WorkerConfig: &porterv1.WorkerServiceConfig{
 					Autoscaling: nil,
@@ -116,7 +115,6 @@ var result_nobuild = &porterv1.PorterApp{
 		{
 			Name:           "example-web",
 			RunOptional:    pointer.String("node index.js"),
-			Instances:      0,
 			Port:           8080,
 			CpuCores:       0.1,
 			RamMegabytes:   256,
@@ -147,13 +145,13 @@ var result_nobuild = &porterv1.PorterApp{
 			Type: 1,
 		},
 		{
-			Name:           "example-wkr",
-			RunOptional:    pointer.String("echo 'work'"),
-			Instances:      1,
-			Port:           80,
-			CpuCores:       0.1,
-			RamMegabytes:   256,
-			GpuCoresNvidia: 0,
+			Name:              "example-wkr",
+			RunOptional:       pointer.String("echo 'work'"),
+			InstancesOptional: pointer.Int32(1),
+			Port:              80,
+			CpuCores:          0.1,
+			RamMegabytes:      256,
+			GpuCoresNvidia:    0,
 			Config: &porterv1.Service_WorkerConfig{
 				WorkerConfig: &porterv1.WorkerServiceConfig{
 					Autoscaling: nil,
@@ -180,7 +178,6 @@ var result_nobuild = &porterv1.PorterApp{
 	},
 	Predeploy: &porterv1.Service{
 		RunOptional:    pointer.String("ls"),
-		Instances:      0,
 		Port:           0,
 		CpuCores:       0,
 		RamMegabytes:   0,

+ 3 - 3
internal/porter_app/v2/yaml.go

@@ -119,7 +119,7 @@ type Service struct {
 	Name               string            `yaml:"name,omitempty"`
 	Run                *string           `yaml:"run,omitempty"`
 	Type               ServiceType       `yaml:"type,omitempty" validate:"required, oneof=web worker job"`
-	Instances          int               `yaml:"instances,omitempty"`
+	Instances          *int32            `yaml:"instances,omitempty"`
 	CpuCores           float32           `yaml:"cpuCores,omitempty"`
 	RamMegabytes       int               `yaml:"ramMegabytes,omitempty"`
 	GpuCoresNvidia     float32           `yaml:"gpuCoresNvidia,omitempty"`
@@ -259,7 +259,7 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
 	serviceProto := &porterv1.Service{
 		Name:              service.Name,
 		RunOptional:       service.Run,
-		Instances:         int32(service.Instances),
+		InstancesOptional: service.Instances,
 		CpuCores:          service.CpuCores,
 		RamMegabytes:      int32(service.RamMegabytes),
 		GpuCoresNvidia:    service.GpuCoresNvidia,
@@ -410,7 +410,7 @@ func appServiceFromProto(service *porterv1.Service) (Service, error) {
 	appService := Service{
 		Name:              service.Name,
 		Run:               service.RunOptional,
-		Instances:         int(service.Instances),
+		Instances:         service.InstancesOptional,
 		CpuCores:          service.CpuCores,
 		RamMegabytes:      int(service.RamMegabytes),
 		GpuCoresNvidia:    service.GpuCoresNvidia,