Parcourir la source

remove deprecated fields (#3999)

d-g-town il y a 2 ans
Parent
commit
75a40d2862

+ 0 - 0
Procfile


+ 38 - 32
internal/porter_app/test/parse_test.go

@@ -191,6 +191,12 @@ var result_nobuild = &porterv1.PorterApp{
 	},
 }
 
+var (
+	trueBool  = true
+	zeroInt32 = int32(0)
+	oneInt32  = int32(1)
+)
+
 var v1_result_nobuild_no_image = &porterv1.PorterApp{
 	Name: "test-app",
 	Services: map[string]*porterv1.Service{
@@ -202,20 +208,20 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
 			GpuCoresNvidia: 0,
 			Config: &porterv1.Service_JobConfig{
 				JobConfig: &porterv1.JobServiceConfig{
-					AllowConcurrent: true,
-					Cron:            "*/10 * * * *",
+					AllowConcurrentOptional: &trueBool,
+					Cron:                    "*/10 * * * *",
 				},
 			},
 			Type: 3,
 		},
 		"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: &oneInt32,
+			Port:              80,
+			CpuCores:          0.1,
+			RamMegabytes:      256,
+			GpuCoresNvidia:    0,
 			Config: &porterv1.Service_WorkerConfig{
 				WorkerConfig: &porterv1.WorkerServiceConfig{
 					Autoscaling: nil,
@@ -224,13 +230,13 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
 			Type: 2,
 		},
 		"example-web": {
-			Name:           "example-web",
-			RunOptional:    pointer.String("node index.js"),
-			Instances:      0,
-			Port:           8080,
-			CpuCores:       0.1,
-			GpuCoresNvidia: 0,
-			RamMegabytes:   256,
+			Name:              "example-web",
+			RunOptional:       pointer.String("node index.js"),
+			InstancesOptional: &zeroInt32,
+			Port:              8080,
+			CpuCores:          0.1,
+			GpuCoresNvidia:    0,
+			RamMegabytes:      256,
 			Config: &porterv1.Service_WebConfig{
 				WebConfig: &porterv1.WebServiceConfig{
 					Autoscaling: &porterv1.Autoscaling{
@@ -267,20 +273,20 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
 			GpuCoresNvidia: 0,
 			Config: &porterv1.Service_JobConfig{
 				JobConfig: &porterv1.JobServiceConfig{
-					AllowConcurrent: true,
-					Cron:            "*/10 * * * *",
+					AllowConcurrentOptional: &trueBool,
+					Cron:                    "*/10 * * * *",
 				},
 			},
 			Type: 3,
 		},
 		{
-			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: &oneInt32,
+			Port:              80,
+			CpuCores:          0.1,
+			RamMegabytes:      256,
+			GpuCoresNvidia:    0,
 			Config: &porterv1.Service_WorkerConfig{
 				WorkerConfig: &porterv1.WorkerServiceConfig{
 					Autoscaling: nil,
@@ -289,13 +295,13 @@ var v1_result_nobuild_no_image = &porterv1.PorterApp{
 			Type: 2,
 		},
 		{
-			Name:           "example-web",
-			RunOptional:    pointer.String("node index.js"),
-			Instances:      0,
-			Port:           8080,
-			CpuCores:       0.1,
-			RamMegabytes:   256,
-			GpuCoresNvidia: 0,
+			Name:              "example-web",
+			RunOptional:       pointer.String("node index.js"),
+			InstancesOptional: &zeroInt32,
+			Port:              8080,
+			CpuCores:          0.1,
+			RamMegabytes:      256,
+			GpuCoresNvidia:    0,
 			Config: &porterv1.Service_WebConfig{
 				WebConfig: &porterv1.WebServiceConfig{
 					Autoscaling: &porterv1.Autoscaling{

+ 2 - 2
internal/porter_app/v1/types.go

@@ -6,10 +6,10 @@ type ServiceConfig struct {
 	Container        Container         `yaml:"container"`
 	Health           *Health           `yaml:"health,omitempty" validate:"excluded_unless=Type web"`
 	Ingress          *Ingress          `yaml:"ingress"`
-	ReplicaCount     string            `yaml:"replicaCount"`
+	ReplicaCount     *string           `yaml:"replicaCount"`
 	Resources        Resources         `yaml:"resources"`
 	Service          KubernetesService `yaml:"service"`
-	AllowConcurrency bool              `yaml:"allowConcurrent" validate:"excluded_unless=Type job"`
+	AllowConcurrency *bool             `yaml:"allowConcurrent" validate:"excluded_unless=Type job"`
 	Schedule         Schedule          `yaml:"schedule" validate:"excluded_unless=Type job"`
 }
 

+ 11 - 8
internal/porter_app/v1/yaml.go

@@ -132,13 +132,16 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
 		Type:        serviceType,
 	}
 
-	// if the revision number cannot be converted, it will default to 0
-	replicaCount, _ := strconv.Atoi(service.Config.ReplicaCount)
-	if replicaCount < math.MinInt32 || replicaCount > math.MaxInt32 {
-		return nil, fmt.Errorf("replica count is out of range of int32")
+	if service.Config.ReplicaCount != nil {
+		// if the revision number cannot be converted, it will default to 0
+		replicaCount, _ := strconv.Atoi(*service.Config.ReplicaCount)
+		if replicaCount < math.MinInt32 || replicaCount > math.MaxInt32 {
+			return nil, fmt.Errorf("replica count is out of range of int32")
+		}
+		// nolint:gosec
+		int32Value := int32(replicaCount)
+		serviceProto.InstancesOptional = &int32Value
 	}
-	// nolint:gosec
-	serviceProto.Instances = int32(replicaCount)
 
 	if service.Config.Resources.Requests.Cpu != "" {
 		cpuCoresStr := service.Config.Resources.Requests.Cpu
@@ -220,8 +223,8 @@ func serviceProtoFromConfig(service Service, serviceType porterv1.ServiceType) (
 		}
 	case porterv1.ServiceType_SERVICE_TYPE_JOB:
 		jobConfig := &porterv1.JobServiceConfig{
-			AllowConcurrent: service.Config.AllowConcurrency,
-			Cron:            service.Config.Schedule.Value,
+			AllowConcurrentOptional: service.Config.AllowConcurrency,
+			Cron:                    service.Config.Schedule.Value,
 		}
 
 		serviceProto.Config = &porterv1.Service_JobConfig{