From 12e6c64ab0178b9a27efcb7455ad9be0d5541780 Mon Sep 17 00:00:00 2001 From: Danail Branekov Date: Mon, 9 Sep 2024 10:06:20 +0000 Subject: [PATCH] Fix gosec errors * Use `int32` for ports (Gateway API ports use that type) * Use `int32` for timeouts, desired instances (pod healtcheck timeout is `int32`) * Use `int64` for limits (k8s resources limits are `int64` Thus we do not have to cast ints all over the place and fix gosec issues Co-authored-by: Yusmen Zabanov --- api/actions/manifest/applier_test.go | 22 +++--- api/actions/manifest/normalizer_test.go | 72 +++++++++---------- api/handlers/app.go | 2 +- api/handlers/app_test.go | 4 +- api/handlers/process.go | 2 +- api/handlers/process_test.go | 12 ++-- api/handlers/route_test.go | 4 +- api/handlers/space_manifest_test.go | 12 ++-- api/payloads/manifest.go | 34 +++++---- api/payloads/manifest_test.go | 22 +++--- api/payloads/process.go | 6 +- api/payloads/process_test.go | 4 +- api/payloads/route.go | 2 +- api/payloads/route_test.go | 2 +- api/presenter/process.go | 21 +++--- api/presenter/route.go | 2 +- api/presenter/route_test.go | 4 +- api/repositories/process_repository.go | 16 ++--- api/repositories/process_repository_test.go | 36 +++++----- api/repositories/repositories_suite_test.go | 2 +- api/repositories/route_repository.go | 4 +- api/repositories/route_repository_test.go | 22 +++--- controllers/api/v1alpha1/cfprocess_types.go | 6 +- controllers/api/v1alpha1/cfprocess_webhook.go | 8 +-- .../api/v1alpha1/cfprocess_webhook_test.go | 12 ++-- controllers/api/v1alpha1/cfroute_types.go | 2 +- .../api/v1alpha1/zz_generated.deepcopy.go | 4 +- controllers/config/config.go | 6 +- controllers/config/config_test.go | 12 ++-- .../networking/routes/controller.go | 4 +- .../networking/routes/controller_test.go | 4 +- .../controllers/workloads/env/builder_test.go | 2 +- .../workloads/k8sns/space_apps_finalizer.go | 4 +- .../controllers/workloads/ports/ports_test.go | 4 +- .../workloads/processes/controller_test.go | 6 +- .../workloads/spaces/controller.go | 4 +- .../workloads/spaces/suite_test.go | 2 +- .../korifi.cloudfoundry.org_cfprocesses.yaml | 5 +- .../korifi.cloudfoundry.org_cfroutes.yaml | 2 + scripts/run-tests.sh | 4 ++ tools/image/client.go | 2 +- 41 files changed, 203 insertions(+), 197 deletions(-) diff --git a/api/actions/manifest/applier_test.go b/api/actions/manifest/applier_test.go index 5baeb27a6..c3a31cb66 100644 --- a/api/actions/manifest/applier_test.go +++ b/api/actions/manifest/applier_test.go @@ -156,22 +156,22 @@ var _ = Describe("Applier", func() { Command: tools.PtrTo("echo foo"), DiskQuota: tools.PtrTo("512M"), HealthCheckHTTPEndpoint: tools.PtrTo("foo/bar"), - HealthCheckInvocationTimeout: tools.PtrTo(int64(10)), + HealthCheckInvocationTimeout: tools.PtrTo(int32(10)), HealthCheckType: tools.PtrTo("http"), - Instances: tools.PtrTo(2), + Instances: tools.PtrTo[int32](2), Memory: tools.PtrTo("756M"), - Timeout: tools.PtrTo(int64(31)), + Timeout: tools.PtrTo(int32(31)), }, { Type: "ben", Command: tools.PtrTo("echo bar"), DiskQuota: tools.PtrTo("256M"), HealthCheckHTTPEndpoint: tools.PtrTo("bar/foo"), - HealthCheckInvocationTimeout: tools.PtrTo(int64(20)), + HealthCheckInvocationTimeout: tools.PtrTo(int32(20)), HealthCheckType: tools.PtrTo("port"), - Instances: tools.PtrTo(3), + Instances: tools.PtrTo[int32](3), Memory: tools.PtrTo("1024M"), - Timeout: tools.PtrTo(int64(45)), + Timeout: tools.PtrTo(int32(45)), }, } }) @@ -188,7 +188,7 @@ var _ = Describe("Applier", func() { Expect(createMsg.Command).To(Equal("echo foo")) Expect(createMsg.DiskQuotaMB).To(BeEquivalentTo(512)) Expect(createMsg.MemoryMB).To(BeEquivalentTo(756)) - Expect(createMsg.DesiredInstances).To(PointTo(Equal(2))) + Expect(createMsg.DesiredInstances).To(PointTo(BeEquivalentTo(2))) Expect(createMsg.HealthCheck).To(Equal(repositories.HealthCheck{ Type: "http", Data: repositories.HealthCheckData{ @@ -205,7 +205,7 @@ var _ = Describe("Applier", func() { Expect(createMsg.Command).To(Equal("echo bar")) Expect(createMsg.DiskQuotaMB).To(BeEquivalentTo(256)) Expect(createMsg.MemoryMB).To(BeEquivalentTo(1024)) - Expect(createMsg.DesiredInstances).To(PointTo(Equal(3))) + Expect(createMsg.DesiredInstances).To(PointTo(BeEquivalentTo(3))) Expect(createMsg.HealthCheck).To(Equal(repositories.HealthCheck{ Type: "port", Data: repositories.HealthCheckData{ @@ -244,11 +244,11 @@ var _ = Describe("Applier", func() { Expect(patchMsg.Command).To(Equal(tools.PtrTo("echo bar"))) Expect(patchMsg.DiskQuotaMB).To(Equal(tools.PtrTo(int64(256)))) Expect(patchMsg.MemoryMB).To(Equal(tools.PtrTo(int64(1024)))) - Expect(patchMsg.DesiredInstances).To(Equal(tools.PtrTo(3))) + Expect(patchMsg.DesiredInstances).To(PointTo(BeEquivalentTo(3))) Expect(patchMsg.HealthCheckType).To(Equal(tools.PtrTo("port"))) Expect(patchMsg.HealthCheckHTTPEndpoint).To(Equal(tools.PtrTo("bar/foo"))) - Expect(patchMsg.HealthCheckInvocationTimeoutSeconds).To(Equal(tools.PtrTo(int64(20)))) - Expect(patchMsg.HealthCheckTimeoutSeconds).To(Equal(tools.PtrTo(int64(45)))) + Expect(patchMsg.HealthCheckInvocationTimeoutSeconds).To(Equal(tools.PtrTo(int32(20)))) + Expect(patchMsg.HealthCheckTimeoutSeconds).To(Equal(tools.PtrTo(int32(45)))) }) When("patching the process fails", func() { diff --git a/api/actions/manifest/normalizer_test.go b/api/actions/manifest/normalizer_test.go index 740ee8d45..51e883f86 100644 --- a/api/actions/manifest/normalizer_test.go +++ b/api/actions/manifest/normalizer_test.go @@ -14,11 +14,11 @@ type prcParams struct { Command *string Memory *string DiskQuota *string - Instances *int + Instances *int32 HealthCheckHTTPEndpoint *string - HealthCheckInvocationTimeout *int64 + HealthCheckInvocationTimeout *int32 HealthCheckType *string - Timeout *int64 + Timeout *int32 } type ( @@ -206,8 +206,8 @@ var _ = Describe("Normalizer", func() { appParams{DiskQuota: tools.PtrTo("2G")}, prcParams{}, expParams{DiskQuota: tools.PtrTo("2G")}), Entry("app-level instances only", - appParams{Instances: tools.PtrTo(3)}, prcParams{}, - expParams{Instances: tools.PtrTo(3)}), + appParams{Instances: tools.PtrTo[int32](3)}, prcParams{}, + expParams{Instances: tools.PtrTo[int32](3)}), Entry("app-level healthcheck endpoint only", appParams{HealthCheckHTTPEndpoint: tools.PtrTo("/health")}, prcParams{}, expParams{HealthCheckHTTPEndpoint: tools.PtrTo("/health")}), @@ -215,11 +215,11 @@ var _ = Describe("Normalizer", func() { appParams{HealthCheckType: tools.PtrTo("typo")}, prcParams{}, expParams{HealthCheckType: tools.PtrTo("typo")}), Entry("app-level healthcheck invocation timeout only", - appParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(64))}, prcParams{}, - expParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(64))}), + appParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(64))}, prcParams{}, + expParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(64))}), Entry("app-level timeout only", - appParams{Timeout: tools.PtrTo(int64(12))}, prcParams{}, - expParams{Timeout: tools.PtrTo(int64(12))}), + appParams{Timeout: tools.PtrTo(int32(12))}, prcParams{}, + expParams{Timeout: tools.PtrTo(int32(12))}), Entry("a combination of fields", appParams{Memory: tools.PtrTo("512M"), DiskQuota: tools.PtrTo("2G")}, prcParams{}, expParams{Memory: tools.PtrTo("512M"), DiskQuota: tools.PtrTo("2G")}), @@ -227,36 +227,36 @@ var _ = Describe("Normalizer", func() { // with an explicit web process in the manifest, but without the app-level value set Entry("empty proc with app memory", appParams{Memory: tools.PtrTo("512M")}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{Memory: tools.PtrTo("512M"), Instances: tools.PtrTo(3)}), + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{Memory: tools.PtrTo("512M"), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with disk quota", appParams{DiskQuota: tools.PtrTo("2G")}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{DiskQuota: tools.PtrTo("2G"), Instances: tools.PtrTo(3)}), + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{DiskQuota: tools.PtrTo("2G"), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with instances", - appParams{Instances: tools.PtrTo(3)}, + appParams{Instances: tools.PtrTo[int32](3)}, prcParams{Memory: tools.PtrTo("512M")}, - expParams{Instances: tools.PtrTo(3), Memory: tools.PtrTo("512M")}), + expParams{Instances: tools.PtrTo[int32](3), Memory: tools.PtrTo("512M")}), Entry("empty proc with command", appParams{Command: tools.PtrTo("echo foo")}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{Command: tools.PtrTo("echo foo"), Instances: tools.PtrTo(3)}), + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{Command: tools.PtrTo("echo foo"), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with healthcheck endpoint", appParams{HealthCheckHTTPEndpoint: tools.PtrTo("/health")}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{HealthCheckHTTPEndpoint: tools.PtrTo("/health"), Instances: tools.PtrTo(3)}), + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{HealthCheckHTTPEndpoint: tools.PtrTo("/health"), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with healthcheck type", appParams{HealthCheckType: tools.PtrTo("type1")}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{HealthCheckType: tools.PtrTo("type1"), Instances: tools.PtrTo(3)}), + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{HealthCheckType: tools.PtrTo("type1"), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with healthcheck invocation timeout", - appParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(45))}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(45)), Instances: tools.PtrTo(3)}), + appParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(45))}, + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(45)), Instances: tools.PtrTo[int32](3)}), Entry("empty proc with timeout", - appParams{Timeout: tools.PtrTo(int64(32))}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{Timeout: tools.PtrTo(int64(32)), Instances: tools.PtrTo(3)}), + appParams{Timeout: tools.PtrTo(int32(32))}, + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{Timeout: tools.PtrTo(int32(32)), Instances: tools.PtrTo[int32](3)}), // with an existing web process with the given value set Entry("value from proc memory used", @@ -268,9 +268,9 @@ var _ = Describe("Normalizer", func() { prcParams{DiskQuota: tools.PtrTo("3G")}, expParams{DiskQuota: tools.PtrTo("3G")}), Entry("value from proc instances used", - appParams{Instances: tools.PtrTo(2)}, - prcParams{Instances: tools.PtrTo(3)}, - expParams{Instances: tools.PtrTo(3)}), + appParams{Instances: tools.PtrTo[int32](2)}, + prcParams{Instances: tools.PtrTo[int32](3)}, + expParams{Instances: tools.PtrTo[int32](3)}), Entry("value from proc command used", appParams{Command: tools.PtrTo("echo bar")}, prcParams{Command: tools.PtrTo("echo foo")}, @@ -284,13 +284,13 @@ var _ = Describe("Normalizer", func() { prcParams{HealthCheckType: tools.PtrTo("proctype")}, expParams{HealthCheckType: tools.PtrTo("proctype")}), Entry("value from proc healthcheck invocation timeout used", - appParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(345))}, - prcParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(34))}, - expParams{HealthCheckInvocationTimeout: tools.PtrTo(int64(34))}), + appParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(345))}, + prcParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(34))}, + expParams{HealthCheckInvocationTimeout: tools.PtrTo(int32(34))}), Entry("value from proc timeout used", - appParams{Timeout: tools.PtrTo(int64(25))}, - prcParams{Timeout: tools.PtrTo(int64(2))}, - expParams{Timeout: tools.PtrTo(int64(2))}), + appParams{Timeout: tools.PtrTo(int32(25))}, + prcParams{Timeout: tools.PtrTo(int32(2))}, + expParams{Timeout: tools.PtrTo(int32(2))}), ) }) diff --git a/api/handlers/app.go b/api/handlers/app.go index fa8495221..bc37f1854 100644 --- a/api/handlers/app.go +++ b/api/handlers/app.go @@ -719,7 +719,7 @@ func (h *App) restartInstance(r *http.Request) (*routing.Response, error) { "InstanceID", instanceID, ) } - if process.DesiredInstances <= instance { + if int(process.DesiredInstances) <= instance { return nil, apierrors.LogAndReturn(logger, apierrors.NewNotFoundError(nil, fmt.Sprintf("Instance %d of process %s", instance, processType)), "Instance not found", "AppGUID", appGUID, "InstanceID", instanceID, "Process", process) } diff --git a/api/handlers/app_test.go b/api/handlers/app_test.go index cfc8317a2..ee245dab3 100644 --- a/api/handlers/app_test.go +++ b/api/handlers/app_test.go @@ -1082,7 +1082,7 @@ var _ = Describe("App", func() { }, nil) payload = &payloads.ProcessScale{ - Instances: tools.PtrTo(5), + Instances: tools.PtrTo[int32](5), MemoryMB: tools.PtrTo[int64](256), DiskMB: tools.PtrTo[int64](1024), } @@ -1116,7 +1116,7 @@ var _ = Describe("App", func() { GUID: "process-1-guid", SpaceGUID: spaceGUID, ProcessScaleValues: repositories.ProcessScaleValues{ - Instances: tools.PtrTo(5), + Instances: tools.PtrTo[int32](5), MemoryMB: tools.PtrTo[int64](256), DiskMB: tools.PtrTo[int64](1024), }, diff --git a/api/handlers/process.go b/api/handlers/process.go index 1be816d41..fbad3680e 100644 --- a/api/handlers/process.go +++ b/api/handlers/process.go @@ -112,7 +112,7 @@ func (h *Process) restartProcessInstance(r *http.Request) (*routing.Response, er "InstanceID", instanceID, ) } - if process.DesiredInstances <= instance { + if int(process.DesiredInstances) <= instance { return nil, apierrors.LogAndReturn(logger, apierrors.NewNotFoundError(nil, fmt.Sprintf("Instance %d of process %s", instance, process.Type)), "Instance not found", "AppGUID", process.AppGUID, "InstanceID", instanceID, "Process", process.Type) } diff --git a/api/handlers/process_test.go b/api/handlers/process_test.go index 88b40137e..22a691653 100644 --- a/api/handlers/process_test.go +++ b/api/handlers/process_test.go @@ -148,7 +148,7 @@ var _ = Describe("Process", func() { }, nil) requestValidator.DecodeAndValidateJSONPayloadStub = decodeAndValidatePayloadStub(&payloads.ProcessScale{ - Instances: tools.PtrTo(3), + Instances: tools.PtrTo[int32](3), MemoryMB: tools.PtrTo[int64](512), DiskMB: tools.PtrTo[int64](256), }) @@ -177,7 +177,7 @@ var _ = Describe("Process", func() { GUID: "process-guid", SpaceGUID: spaceGUID, ProcessScaleValues: repositories.ProcessScaleValues{ - Instances: tools.PtrTo(3), + Instances: tools.PtrTo[int32](3), MemoryMB: tools.PtrTo(int64(512)), DiskMB: tools.PtrTo(int64(256)), }, @@ -380,9 +380,9 @@ var _ = Describe("Process", func() { HealthCheck: &payloads.HealthCheck{ Type: tools.PtrTo("port"), Data: &payloads.Data{ - Timeout: tools.PtrTo[int64](5), + Timeout: tools.PtrTo[int32](5), Endpoint: tools.PtrTo("http://myapp.com/health"), - InvocationTimeout: tools.PtrTo[int64](2), + InvocationTimeout: tools.PtrTo[int32](2), }, }, }) @@ -403,8 +403,8 @@ var _ = Describe("Process", func() { _, actualAuthInfo, actualMsg := processRepo.PatchProcessArgsForCall(0) Expect(actualAuthInfo).To(Equal(authInfo)) Expect(actualMsg.ProcessGUID).To(Equal("process-guid")) - Expect(actualMsg.HealthCheckInvocationTimeoutSeconds).To(Equal(tools.PtrTo(int64(2)))) - Expect(actualMsg.HealthCheckTimeoutSeconds).To(Equal(tools.PtrTo(int64(5)))) + Expect(actualMsg.HealthCheckInvocationTimeoutSeconds).To(Equal(tools.PtrTo(int32(2)))) + Expect(actualMsg.HealthCheckTimeoutSeconds).To(Equal(tools.PtrTo(int32(5)))) Expect(actualMsg.HealthCheckHTTPEndpoint).To(Equal(tools.PtrTo("http://myapp.com/health"))) Expect(actualMsg.HealthCheckType).To(Equal(tools.PtrTo("port"))) Expect(actualMsg.MetadataPatch.Labels).To(Equal(map[string]*string{"foo": tools.PtrTo("value1")})) diff --git a/api/handlers/route_test.go b/api/handlers/route_test.go index 916bf3813..01c03bcdd 100644 --- a/api/handlers/route_test.go +++ b/api/handlers/route_test.go @@ -574,7 +574,7 @@ var _ = Describe("Route", func() { Type: "queue", }, }, - Port: tools.PtrTo(1234), + Port: tools.PtrTo[int32](1234), Protocol: tools.PtrTo("http1"), }, }, @@ -612,7 +612,7 @@ var _ = Describe("Route", func() { MatchFields(IgnoreExtras, Fields{ "AppGUID": Equal("app-2-guid"), "ProcessType": Equal("queue"), - "Port": PointTo(Equal(1234)), + "Port": PointTo(BeEquivalentTo(1234)), "Protocol": PointTo(Equal("http1")), }), )) diff --git a/api/handlers/space_manifest_test.go b/api/handlers/space_manifest_test.go index 72f36afdd..ba6648e45 100644 --- a/api/handlers/space_manifest_test.go +++ b/api/handlers/space_manifest_test.go @@ -65,11 +65,11 @@ var _ = Describe("SpaceManifest", func() { Command: tools.PtrTo("start-web.sh"), DiskQuota: tools.PtrTo("512M"), HealthCheckHTTPEndpoint: tools.PtrTo("/healthcheck"), - HealthCheckInvocationTimeout: tools.PtrTo[int64](5), + HealthCheckInvocationTimeout: tools.PtrTo[int32](5), HealthCheckType: tools.PtrTo("http"), - Instances: tools.PtrTo(1), + Instances: tools.PtrTo[int32](1), Memory: tools.PtrTo("256M"), - Timeout: tools.PtrTo[int64](10), + Timeout: tools.PtrTo[int32](10), }}, }}, }) @@ -99,11 +99,11 @@ var _ = Describe("SpaceManifest", func() { Expect(payload.Applications[0].Processes[0].Command).To(PointTo(Equal("start-web.sh"))) Expect(payload.Applications[0].Processes[0].DiskQuota).To(PointTo(Equal("512M"))) Expect(payload.Applications[0].Processes[0].HealthCheckHTTPEndpoint).To(PointTo(Equal("/healthcheck"))) - Expect(payload.Applications[0].Processes[0].HealthCheckInvocationTimeout).To(PointTo(Equal(int64(5)))) + Expect(payload.Applications[0].Processes[0].HealthCheckInvocationTimeout).To(PointTo(Equal(int32(5)))) Expect(payload.Applications[0].Processes[0].HealthCheckType).To(PointTo(Equal("http"))) - Expect(payload.Applications[0].Processes[0].Instances).To(PointTo(Equal(1))) + Expect(payload.Applications[0].Processes[0].Instances).To(PointTo(BeEquivalentTo(1))) Expect(payload.Applications[0].Processes[0].Memory).To(PointTo(Equal("256M"))) - Expect(payload.Applications[0].Processes[0].Timeout).To(PointTo(Equal(int64(10)))) + Expect(payload.Applications[0].Processes[0].Timeout).To(PointTo(Equal(int32(10)))) }) When("the manifest is invalid", func() { diff --git a/api/payloads/manifest.go b/api/payloads/manifest.go index 13397887a..a8d39ecbd 100644 --- a/api/payloads/manifest.go +++ b/api/payloads/manifest.go @@ -26,7 +26,7 @@ type ManifestApplication struct { RandomRoute bool `yaml:"random-route"` NoRoute bool `yaml:"no-route"` Command *string `yaml:"command"` - Instances *int `json:"instances" yaml:"instances"` + Instances *int32 `json:"instances" yaml:"instances"` Memory *string `json:"memory" yaml:"memory"` DiskQuota *string `json:"disk_quota" yaml:"disk_quota"` // AltDiskQuota supports `disk-quota` with a hyphen for backwards compatibility. @@ -35,9 +35,9 @@ type ManifestApplication struct { // Deprecated: Use DiskQuota instead AltDiskQuota *string `json:"disk-quota" yaml:"disk-quota"` HealthCheckHTTPEndpoint *string `yaml:"health-check-http-endpoint"` - HealthCheckInvocationTimeout *int64 `json:"health-check-invocation-timeout" yaml:"health-check-invocation-timeout"` + HealthCheckInvocationTimeout *int32 `json:"health-check-invocation-timeout" yaml:"health-check-invocation-timeout"` HealthCheckType *string `json:"health-check-type" yaml:"health-check-type"` - Timeout *int64 `json:"timeout" yaml:"timeout"` + Timeout *int32 `json:"timeout" yaml:"timeout"` Processes []ManifestApplicationProcess `json:"processes" yaml:"processes"` Routes []ManifestRoute `json:"routes" yaml:"routes"` Buildpacks []string `yaml:"buildpacks"` @@ -60,11 +60,11 @@ type ManifestApplicationProcess struct { // Deprecated: Use DiskQuota instead AltDiskQuota *string `json:"disk-quota" yaml:"disk-quota"` HealthCheckHTTPEndpoint *string `yaml:"health-check-http-endpoint"` - HealthCheckInvocationTimeout *int64 `json:"health-check-invocation-timeout" yaml:"health-check-invocation-timeout"` + HealthCheckInvocationTimeout *int32 `json:"health-check-invocation-timeout" yaml:"health-check-invocation-timeout"` HealthCheckType *string `json:"health-check-type" yaml:"health-check-type"` - Instances *int `json:"instances" yaml:"instances"` + Instances *int32 `json:"instances" yaml:"instances"` Memory *string `json:"memory" yaml:"memory"` - Timeout *int64 `json:"timeout" yaml:"timeout"` + Timeout *int32 `json:"timeout" yaml:"timeout"` } type ManifestApplicationService struct { @@ -172,15 +172,11 @@ func (p ManifestApplicationProcess) ToProcessCreateMessage(appGUID, spaceGUID st msg.DesiredInstances = p.Instances if p.Memory != nil { - // error ignored intentionally, since the manifest yaml is validated in handlers - memoryQuotaMB, _ := bytefmt.ToMegabytes(*p.Memory) - msg.MemoryMB = int64(memoryQuotaMB) + msg.MemoryMB = parseMegabytes(*p.Memory) } if p.DiskQuota != nil { - // error ignored intentionally, since the manifest yaml is validated in handlers - diskQuotaMB, _ := bytefmt.ToMegabytes(*p.DiskQuota) - msg.DiskQuotaMB = int64(diskQuotaMB) + msg.DiskQuotaMB = parseMegabytes(*p.DiskQuota) } return msg @@ -203,14 +199,10 @@ func (p ManifestApplicationProcess) ToProcessPatchMessage(processGUID, spaceGUID } } if p.DiskQuota != nil { - diskQuotaMB, _ := bytefmt.ToMegabytes(*p.DiskQuota) - int64DQMB := int64(diskQuotaMB) - message.DiskQuotaMB = &int64DQMB + message.DiskQuotaMB = tools.PtrTo(parseMegabytes(*p.DiskQuota)) } if p.Memory != nil { - memoryMB, _ := bytefmt.ToMegabytes(*p.Memory) - int64MMB := int64(memoryMB) - message.MemoryMB = &int64MMB + message.MemoryMB = tools.PtrTo(parseMegabytes(*p.Memory)) } return message } @@ -287,3 +279,9 @@ func validateAmountWithUnit(value any) error { return nil } + +func parseMegabytes(s string) int64 { + // error intentinally ignored as the manifesst is validated beforehand + mb, _ := bytefmt.ToMegabytes(s) + return int64(mb) // #nosec G115 +} diff --git a/api/payloads/manifest_test.go b/api/payloads/manifest_test.go index e574b70e1..96602ede5 100644 --- a/api/payloads/manifest_test.go +++ b/api/payloads/manifest_test.go @@ -95,7 +95,7 @@ var _ = Describe("Manifest payload", func() { When("Instances is negative", func() { BeforeEach(func() { - testManifest.Instances = tools.PtrTo(-1) + testManifest.Instances = tools.PtrTo[int32](-1) }) It("returns a validation error", func() { @@ -156,7 +156,7 @@ var _ = Describe("Manifest payload", func() { When("HealthCheckInvocationTimeout is not positive", func() { BeforeEach(func() { - testManifest.HealthCheckInvocationTimeout = tools.PtrTo(int64(0)) + testManifest.HealthCheckInvocationTimeout = tools.PtrTo(int32(0)) }) It("returns a validation error", func() { @@ -176,7 +176,7 @@ var _ = Describe("Manifest payload", func() { When("Timeout is not positive", func() { BeforeEach(func() { - testManifest.Timeout = tools.PtrTo(int64(0)) + testManifest.Timeout = tools.PtrTo(int32(0)) }) It("returns a validation error", func() { @@ -469,7 +469,7 @@ var _ = Describe("Manifest payload", func() { When("HealthCheckInvocationTimeout is not positive", func() { BeforeEach(func() { - testManifestProcess.HealthCheckInvocationTimeout = tools.PtrTo(int64(0)) + testManifestProcess.HealthCheckInvocationTimeout = tools.PtrTo(int32(0)) }) It("returns a validation error", func() { @@ -489,7 +489,7 @@ var _ = Describe("Manifest payload", func() { When("Instances is negative", func() { BeforeEach(func() { - testManifestProcess.Instances = tools.PtrTo(-1) + testManifestProcess.Instances = tools.PtrTo[int32](-1) }) It("returns a validation error", func() { @@ -519,7 +519,7 @@ var _ = Describe("Manifest payload", func() { When("Timeout is not positive", func() { BeforeEach(func() { - testManifestProcess.Timeout = tools.PtrTo(int64(0)) + testManifestProcess.Timeout = tools.PtrTo(int32(0)) }) It("returns a validation error", func() { @@ -539,11 +539,11 @@ var _ = Describe("Manifest payload", func() { Command: tools.PtrTo("start-web.sh"), DiskQuota: tools.PtrTo("512M"), HealthCheckHTTPEndpoint: tools.PtrTo("/stuff"), - HealthCheckInvocationTimeout: tools.PtrTo(int64(90)), + HealthCheckInvocationTimeout: tools.PtrTo(int32(90)), HealthCheckType: tools.PtrTo("http"), - Instances: tools.PtrTo(3), + Instances: tools.PtrTo[int32](3), Memory: tools.PtrTo("1G"), - Timeout: tools.PtrTo(int64(60)), + Timeout: tools.PtrTo(int32(60)), } }) @@ -564,7 +564,7 @@ var _ = Describe("Manifest payload", func() { InvocationTimeoutSeconds: 90, }, }, - DesiredInstances: tools.PtrTo(3), + DesiredInstances: tools.PtrTo[int32](3), MemoryMB: 1024, })) }) @@ -694,7 +694,7 @@ var _ = Describe("Manifest payload", func() { When("Instances is specified", func() { BeforeEach(func() { - processInfo.Instances = tools.PtrTo(3) + processInfo.Instances = tools.PtrTo[int32](3) }) It("returns a message with DesiredInstances set to the parsed value", func() { diff --git a/api/payloads/process.go b/api/payloads/process.go index 5e0b35e30..dfda07929 100644 --- a/api/payloads/process.go +++ b/api/payloads/process.go @@ -9,7 +9,7 @@ import ( ) type ProcessScale struct { - Instances *int `json:"instances"` + Instances *int32 `json:"instances"` MemoryMB *int64 `json:"memory_in_mb"` DiskMB *int64 `json:"disk_in_mb"` } @@ -34,9 +34,9 @@ type HealthCheck struct { } type Data struct { - Timeout *int64 `json:"timeout"` + Timeout *int32 `json:"timeout"` Endpoint *string `json:"endpoint"` - InvocationTimeout *int64 `json:"invocation_timeout"` + InvocationTimeout *int32 `json:"invocation_timeout"` } func (p ProcessScale) ToRecord() repositories.ProcessScaleValues { diff --git a/api/payloads/process_test.go b/api/payloads/process_test.go index b81a4943e..2428d20a7 100644 --- a/api/payloads/process_test.go +++ b/api/payloads/process_test.go @@ -37,7 +37,7 @@ var _ = Describe("Process payload validation", func() { BeforeEach(func() { payload = payloads.ProcessScale{ - Instances: tools.PtrTo(1), + Instances: tools.PtrTo[int32](1), MemoryMB: tools.PtrTo[int64](2), DiskMB: tools.PtrTo[int64](3), } @@ -56,7 +56,7 @@ var _ = Describe("Process payload validation", func() { When("instances is negative", func() { BeforeEach(func() { - payload.Instances = tools.PtrTo(-1) + payload.Instances = tools.PtrTo[int32](-1) }) It("returns an error", func() { diff --git a/api/payloads/route.go b/api/payloads/route.go index 66eff1319..48623ebde 100644 --- a/api/payloads/route.go +++ b/api/payloads/route.go @@ -114,7 +114,7 @@ func (r RouteDestinationCreate) Validate() error { type RouteDestination struct { App AppResource `json:"app"` - Port *int `json:"port"` + Port *int32 `json:"port"` Protocol *string `json:"protocol"` } diff --git a/api/payloads/route_test.go b/api/payloads/route_test.go index dd3418beb..7dd90b3cf 100644 --- a/api/payloads/route_test.go +++ b/api/payloads/route_test.go @@ -215,7 +215,7 @@ var _ = Describe("Add destination", func() { Type: "queue", }, }, - Port: tools.PtrTo(1234), + Port: tools.PtrTo[int32](1234), Protocol: tools.PtrTo("http1"), }, }, diff --git a/api/presenter/process.go b/api/presenter/process.go index 268d4068e..4b8483039 100644 --- a/api/presenter/process.go +++ b/api/presenter/process.go @@ -7,6 +7,7 @@ import ( "code.cloudfoundry.org/korifi/api/repositories" "code.cloudfoundry.org/korifi/model" + "code.cloudfoundry.org/korifi/tools" ) const ( @@ -17,7 +18,7 @@ type ProcessResponse struct { GUID string `json:"guid"` Type string `json:"type"` Command string `json:"command"` - Instances int `json:"instances"` + Instances int32 `json:"instances"` MemoryMB int64 `json:"memory_in_mb"` DiskQuotaMB int64 `json:"disk_in_mb"` HealthCheck ProcessResponseHealthCheck `json:"health_check"` @@ -43,8 +44,8 @@ type ProcessResponseHealthCheck struct { type ProcessResponseHealthCheckData struct { Type string `json:"-"` - Timeout int64 `json:"timeout"` - InvocationTimeout int64 `json:"invocation_timeout"` + Timeout int32 `json:"timeout"` + InvocationTimeout int32 `json:"invocation_timeout"` HTTPEndpoint string `json:"endpoint"` } @@ -52,11 +53,11 @@ type ProcessResponseHealthCheckData struct { type respAlias ProcessResponseHealthCheckData func (h ProcessResponseHealthCheckData) MarshalJSON() ([]byte, error) { - timeout := &(h.Timeout) + timeout := tools.PtrTo(h.Timeout) if *timeout == 0 { timeout = nil } - invocationTimeout := &(h.InvocationTimeout) + invocationTimeout := tools.PtrTo(h.InvocationTimeout) if *invocationTimeout == 0 { invocationTimeout = nil } @@ -83,18 +84,18 @@ func (h ProcessResponseHealthCheckData) MarshalJSON() ([]byte, error) { } type ProcessResponseHTTPHealthCheckData struct { - Timeout *int64 `json:"timeout"` - InvocationTimeout *int64 `json:"invocation_timeout"` + Timeout *int32 `json:"timeout"` + InvocationTimeout *int32 `json:"invocation_timeout"` HTTPEndpoint string `json:"endpoint"` } type ProcessResponsePortHealthCheckData struct { - Timeout *int64 `json:"timeout"` - InvocationTimeout *int64 `json:"invocation_timeout"` + Timeout *int32 `json:"timeout"` + InvocationTimeout *int32 `json:"invocation_timeout"` } type ProcessResponseProcessHealthCheckData struct { - Timeout *int64 `json:"timeout"` + Timeout *int32 `json:"timeout"` } func ForProcess(responseProcess repositories.ProcessRecord, baseURL url.URL) ProcessResponse { diff --git a/api/presenter/route.go b/api/presenter/route.go index bf9d1a486..14bd0fd85 100644 --- a/api/presenter/route.go +++ b/api/presenter/route.go @@ -37,7 +37,7 @@ type routeDestination struct { GUID string `json:"guid"` App routeDestinationApp `json:"app"` Weight *int `json:"weight"` - Port *int `json:"port"` + Port *int32 `json:"port"` Protocol *string `json:"protocol"` } diff --git a/api/presenter/route_test.go b/api/presenter/route_test.go index e1bc1c23c..2016bb497 100644 --- a/api/presenter/route_test.go +++ b/api/presenter/route_test.go @@ -39,14 +39,14 @@ var _ = Describe("Route", func() { GUID: "dest-1-guid", AppGUID: "app-1-guid", ProcessType: "web", - Port: tools.PtrTo(1234), + Port: tools.PtrTo[int32](1234), Protocol: tools.PtrTo("http1"), }, { GUID: "dest-2-guid", AppGUID: "app-2-guid", ProcessType: "queue", - Port: tools.PtrTo(5678), + Port: tools.PtrTo[int32](5678), Protocol: tools.PtrTo("http2"), }, }, diff --git a/api/repositories/process_repository.go b/api/repositories/process_repository.go index 1e06cad22..d079399bb 100644 --- a/api/repositories/process_repository.go +++ b/api/repositories/process_repository.go @@ -42,7 +42,7 @@ type ProcessRecord struct { AppGUID string Type string Command string - DesiredInstances int + DesiredInstances int32 MemoryMB int64 DiskQuotaMB int64 HealthCheck HealthCheck @@ -69,8 +69,8 @@ type HealthCheck struct { type HealthCheckData struct { HTTPEndpoint string - InvocationTimeoutSeconds int64 - TimeoutSeconds int64 + InvocationTimeoutSeconds int32 + TimeoutSeconds int32 } type ScaleProcessMessage struct { @@ -80,7 +80,7 @@ type ScaleProcessMessage struct { } type ProcessScaleValues struct { - Instances *int + Instances *int32 MemoryMB *int64 DiskMB *int64 } @@ -92,7 +92,7 @@ type CreateProcessMessage struct { Command string DiskQuotaMB int64 HealthCheck HealthCheck - DesiredInstances *int + DesiredInstances *int32 MemoryMB int64 } @@ -102,10 +102,10 @@ type PatchProcessMessage struct { Command *string DiskQuotaMB *int64 HealthCheckHTTPEndpoint *string - HealthCheckInvocationTimeoutSeconds *int64 - HealthCheckTimeoutSeconds *int64 + HealthCheckInvocationTimeoutSeconds *int32 + HealthCheckTimeoutSeconds *int32 HealthCheckType *string - DesiredInstances *int + DesiredInstances *int32 MemoryMB *int64 MetadataPatch *MetadataPatch } diff --git a/api/repositories/process_repository_test.go b/api/repositories/process_repository_test.go index eafaa27e4..bd2dc6aa5 100644 --- a/api/repositories/process_repository_test.go +++ b/api/repositories/process_repository_test.go @@ -221,7 +221,7 @@ var _ = Describe("ProcessRepo", func() { cfProcess *korifiv1alpha1.CFProcess scaleProcessMessage *repositories.ScaleProcessMessage - instanceScale int + instanceScale int32 diskScaleMB int64 memoryScaleMB int64 ) @@ -252,7 +252,7 @@ var _ = Describe("ProcessRepo", func() { }) DescribeTable("calling ScaleProcess with a set of scale values returns an updated CFProcess record", - func(instances *int, diskMB, memoryMB *int64) { + func(instances *int32, diskMB, memoryMB *int64) { scaleProcessMessage.ProcessScaleValues = repositories.ProcessScaleValues{ Instances: instances, DiskMB: diskMB, @@ -306,16 +306,16 @@ var _ = Describe("ProcessRepo", func() { When("scaling down a process to 0 instances", func() { It("works", func() { - scaleProcessMessage.ProcessScaleValues = repositories.ProcessScaleValues{Instances: tools.PtrTo(0)} + scaleProcessMessage.ProcessScaleValues = repositories.ProcessScaleValues{Instances: tools.PtrTo[int32](0)} scaleProcessRecord, scaleProcessErr := processRepo.ScaleProcess(context.Background(), authInfo, *scaleProcessMessage) Expect(scaleProcessErr).ToNot(HaveOccurred()) - Expect(scaleProcessRecord.DesiredInstances).To(Equal(0)) + Expect(scaleProcessRecord.DesiredInstances).To(BeZero()) var updatedCFProcess korifiv1alpha1.CFProcess Expect(k8sClient.Get(ctx, client.ObjectKey{Name: process1GUID, Namespace: space1.Name}, &updatedCFProcess)).To(Succeed()) - Expect(updatedCFProcess.Spec.DesiredInstances).To(PointTo(Equal(0))) + Expect(updatedCFProcess.Spec.DesiredInstances).To(PointTo(BeZero())) }) }) @@ -346,7 +346,7 @@ var _ = Describe("ProcessRepo", func() { TimeoutSeconds: 10, }, }, - DesiredInstances: tools.PtrTo(42), + DesiredInstances: tools.PtrTo[int32](42), MemoryMB: 456, }) }) @@ -377,7 +377,7 @@ var _ = Describe("ProcessRepo", func() { TimeoutSeconds: 10, }, }, - DesiredInstances: tools.PtrTo(42), + DesiredInstances: tools.PtrTo[int32](42), MemoryMB: 456, DiskQuotaMB: 123, })) @@ -476,7 +476,7 @@ var _ = Describe("ProcessRepo", func() { TimeoutSeconds: 2, }, }, - DesiredInstances: tools.PtrTo(1), + DesiredInstances: tools.PtrTo[int32](1), MemoryMB: 2, DiskQuotaMB: 3, }, @@ -493,9 +493,9 @@ var _ = Describe("ProcessRepo", func() { Command: tools.PtrTo("start-web"), HealthCheckType: tools.PtrTo("http"), HealthCheckHTTPEndpoint: tools.PtrTo("/healthz"), - HealthCheckInvocationTimeoutSeconds: tools.PtrTo(int64(20)), - HealthCheckTimeoutSeconds: tools.PtrTo(int64(10)), - DesiredInstances: tools.PtrTo(42), + HealthCheckInvocationTimeoutSeconds: tools.PtrTo(int32(20)), + HealthCheckTimeoutSeconds: tools.PtrTo(int32(10)), + DesiredInstances: tools.PtrTo[int32](42), MemoryMB: tools.PtrTo(int64(456)), DiskQuotaMB: tools.PtrTo(int64(123)), } @@ -521,9 +521,9 @@ var _ = Describe("ProcessRepo", func() { Command: tools.PtrTo("start-web"), HealthCheckType: tools.PtrTo("http"), HealthCheckHTTPEndpoint: tools.PtrTo("/healthz"), - HealthCheckInvocationTimeoutSeconds: tools.PtrTo(int64(20)), - HealthCheckTimeoutSeconds: tools.PtrTo(int64(10)), - DesiredInstances: tools.PtrTo(42), + HealthCheckInvocationTimeoutSeconds: tools.PtrTo(int32(20)), + HealthCheckTimeoutSeconds: tools.PtrTo(int32(10)), + DesiredInstances: tools.PtrTo[int32](42), MemoryMB: tools.PtrTo(int64(456)), DiskQuotaMB: tools.PtrTo(int64(123)), MetadataPatch: &repositories.MetadataPatch{ @@ -563,7 +563,7 @@ var _ = Describe("ProcessRepo", func() { TimeoutSeconds: 10, }, }, - DesiredInstances: tools.PtrTo(42), + DesiredInstances: tools.PtrTo[int32](42), MemoryMB: 456, DiskQuotaMB: 123, })) @@ -578,8 +578,8 @@ var _ = Describe("ProcessRepo", func() { ProcessGUID: process1GUID, SpaceGUID: space.Name, Command: tools.PtrTo("new-command"), - HealthCheckTimeoutSeconds: tools.PtrTo(int64(42)), - DesiredInstances: tools.PtrTo(5), + HealthCheckTimeoutSeconds: tools.PtrTo(int32(42)), + DesiredInstances: tools.PtrTo[int32](5), MemoryMB: tools.PtrTo(int64(123)), } }) @@ -612,7 +612,7 @@ var _ = Describe("ProcessRepo", func() { TimeoutSeconds: 42, }, }, - DesiredInstances: tools.PtrTo(5), + DesiredInstances: tools.PtrTo[int32](5), MemoryMB: 123, DiskQuotaMB: 3, })) diff --git a/api/repositories/repositories_suite_test.go b/api/repositories/repositories_suite_test.go index b3690b6bf..c4cf5c98a 100644 --- a/api/repositories/repositories_suite_test.go +++ b/api/repositories/repositories_suite_test.go @@ -347,7 +347,7 @@ func createProcessCR(ctx context.Context, k8sClient client.Client, processGUID, TimeoutSeconds: 0, }, }, - DesiredInstances: tools.PtrTo(1), + DesiredInstances: tools.PtrTo[int32](1), MemoryMB: 500, DiskQuotaMB: 512, }, diff --git a/api/repositories/route_repository.go b/api/repositories/route_repository.go index 363cfc1e7..8a86355ee 100644 --- a/api/repositories/route_repository.go +++ b/api/repositories/route_repository.go @@ -44,7 +44,7 @@ type DestinationRecord struct { GUID string AppGUID string ProcessType string - Port *int + Port *int32 Protocol *string // Weight intentionally omitted as experimental features } @@ -74,7 +74,7 @@ func (r RouteRecord) Relationships() map[string]string { type DesiredDestination struct { AppGUID string ProcessType string - Port *int + Port *int32 Protocol *string // Weight intentionally omitted as experimental features } diff --git a/api/repositories/route_repository_test.go b/api/repositories/route_repository_test.go index cc89f4541..07d68cce6 100644 --- a/api/repositories/route_repository_test.go +++ b/api/repositories/route_repository_test.go @@ -81,7 +81,7 @@ var _ = Describe("RouteRepository", func() { Destinations: []korifiv1alpha1.Destination{ { GUID: "destination-guid", - Port: tools.PtrTo(8080), + Port: tools.PtrTo[int32](8080), AppRef: corev1.LocalObjectReference{ Name: "some-app-guid", }, @@ -171,7 +171,7 @@ var _ = Describe("RouteRepository", func() { Name: "some-app-guid", }, ProcessType: "web", - Port: tools.PtrTo(2345), + Port: tools.PtrTo[int32](2345), Protocol: tools.PtrTo("http1"), }}, } @@ -181,7 +181,7 @@ var _ = Describe("RouteRepository", func() { It("returns a destination record with the port in the route status", func() { Expect(getErr).ToNot(HaveOccurred()) Expect(route.Destinations).To(ConsistOf(MatchFields(IgnoreExtras, Fields{ - "Port": PointTo(Equal(2345)), + "Port": PointTo(BeEquivalentTo(2345)), "Protocol": PointTo(Equal("http1")), }))) }) @@ -440,7 +440,7 @@ var _ = Describe("RouteRepository", func() { Destinations: []korifiv1alpha1.Destination{ { GUID: "destination-guid", - Port: tools.PtrTo(8080), + Port: tools.PtrTo[int32](8080), AppRef: corev1.LocalObjectReference{ Name: appGUID, }, @@ -623,7 +623,7 @@ var _ = Describe("RouteRepository", func() { Destinations: []korifiv1alpha1.Destination{ { GUID: "destination-guid", - Port: tools.PtrTo(8080), + Port: tools.PtrTo[int32](8080), AppRef: corev1.LocalObjectReference{ Name: "some-app-guid", }, @@ -796,7 +796,7 @@ var _ = Describe("RouteRepository", func() { { AppGUID: appGUID, ProcessType: "web", - Port: tools.PtrTo(9090), + Port: tools.PtrTo[int32](9090), Protocol: tools.PtrTo("http1"), }, }, @@ -837,7 +837,7 @@ var _ = Describe("RouteRepository", func() { MatchAllFields( Fields{ "GUID": Not(BeEmpty()), - "Port": PointTo(Equal(9090)), + "Port": PointTo(BeEquivalentTo(9090)), "AppGUID": Equal(appGUID), "ProcessType": Equal("web"), "Protocol": PointTo(Equal("http1")), @@ -849,7 +849,7 @@ var _ = Describe("RouteRepository", func() { MatchAllFields( Fields{ "GUID": Not(BeEmpty()), - "Port": PointTo(Equal(9090)), + "Port": PointTo(BeEquivalentTo(9090)), "AppRef": Equal(corev1.LocalObjectReference{ Name: appGUID, }), @@ -904,7 +904,7 @@ var _ = Describe("RouteRepository", func() { BeforeEach(func() { routeDestination = korifiv1alpha1.Destination{ GUID: prefixedGUID("existing-route-guid"), - Port: tools.PtrTo(8000), + Port: tools.PtrTo[int32](8000), AppRef: corev1.LocalObjectReference{ Name: prefixedGUID("existing-route-app"), }, @@ -1076,7 +1076,7 @@ var _ = Describe("RouteRepository", func() { }, Destinations: []korifiv1alpha1.Destination{{ GUID: destinationGUID, - Port: tools.PtrTo(8000), + Port: tools.PtrTo[int32](8000), AppRef: corev1.LocalObjectReference{ Name: uuid.NewString(), }, @@ -1378,7 +1378,7 @@ var _ = Describe("RouteRepository", func() { Destinations: []korifiv1alpha1.Destination{ { GUID: "destination-guid", - Port: tools.PtrTo(8080), + Port: tools.PtrTo[int32](8080), AppRef: corev1.LocalObjectReference{ Name: "some-app-guid", }, diff --git a/controllers/api/v1alpha1/cfprocess_types.go b/controllers/api/v1alpha1/cfprocess_types.go index 239741736..034f3addf 100644 --- a/controllers/api/v1alpha1/cfprocess_types.go +++ b/controllers/api/v1alpha1/cfprocess_types.go @@ -46,7 +46,7 @@ type CFProcessSpec struct { HealthCheck HealthCheck `json:"healthCheck"` // The desired number of replicas to deploy - DesiredInstances *int `json:"desiredInstances,omitempty"` + DesiredInstances *int32 `json:"desiredInstances,omitempty"` // The memory limit in MiB MemoryMB int64 `json:"memoryMB"` @@ -79,8 +79,8 @@ type HealthCheckData struct { // The http endpoint to use with "http" healthchecks HTTPEndpoint string `json:"httpEndpoint,omitempty"` - InvocationTimeoutSeconds int64 `json:"invocationTimeoutSeconds"` - TimeoutSeconds int64 `json:"timeoutSeconds"` + InvocationTimeoutSeconds int32 `json:"invocationTimeoutSeconds"` + TimeoutSeconds int32 `json:"timeoutSeconds"` } // CFProcessStatus defines the observed state of CFProcess diff --git a/controllers/api/v1alpha1/cfprocess_webhook.go b/controllers/api/v1alpha1/cfprocess_webhook.go index 85a46331f..321628c43 100644 --- a/controllers/api/v1alpha1/cfprocess_webhook.go +++ b/controllers/api/v1alpha1/cfprocess_webhook.go @@ -31,10 +31,10 @@ var cfprocesslog = logf.Log.WithName("cfprocess-resource") type CFProcessDefaulter struct { defaultMemoryMB int64 defaultDiskQuotaMB int64 - defaultTimeout int64 + defaultTimeout int32 } -func NewCFProcessDefaulter(defaultMemoryMB, defaultDiskQuotaMB int64, defaultTimeout int64) *CFProcessDefaulter { +func NewCFProcessDefaulter(defaultMemoryMB, defaultDiskQuotaMB int64, defaultTimeout int32) *CFProcessDefaulter { return &CFProcessDefaulter{ defaultMemoryMB: defaultMemoryMB, defaultDiskQuotaMB: defaultDiskQuotaMB, @@ -92,11 +92,11 @@ func (d *CFProcessDefaulter) defaultInstances(process *CFProcess) { return } - defaultInstances := 0 + defaultInstances := int32(0) if process.Spec.ProcessType == ProcessTypeWeb { defaultInstances = 1 } - process.Spec.DesiredInstances = tools.PtrTo(defaultInstances) + process.Spec.DesiredInstances = tools.PtrTo[int32](defaultInstances) } func (d *CFProcessDefaulter) defaultHealthCheck(process *CFProcess) { diff --git a/controllers/api/v1alpha1/cfprocess_webhook_test.go b/controllers/api/v1alpha1/cfprocess_webhook_test.go index 5d07c5f5e..1b5292238 100644 --- a/controllers/api/v1alpha1/cfprocess_webhook_test.go +++ b/controllers/api/v1alpha1/cfprocess_webhook_test.go @@ -106,16 +106,16 @@ var _ = Describe("CFProcessMutatingWebhook", func() { Describe("instances", func() { It("defaults desired instances to zero", func() { - Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(Equal(0))) + Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(BeZero())) }) When("the process has the instance number set", func() { BeforeEach(func() { - cfProcess.Spec.DesiredInstances = tools.PtrTo(24) + cfProcess.Spec.DesiredInstances = tools.PtrTo[int32](24) }) It("leaves instances unchanged", func() { - Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(Equal(24))) + Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(BeEquivalentTo(24))) }) }) @@ -125,16 +125,16 @@ var _ = Describe("CFProcessMutatingWebhook", func() { }) It("defaults instances to 1", func() { - Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(Equal(1))) + Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(BeEquivalentTo(1))) }) When("the process has the instance number set", func() { BeforeEach(func() { - cfProcess.Spec.DesiredInstances = tools.PtrTo(42) + cfProcess.Spec.DesiredInstances = tools.PtrTo[int32](42) }) It("leaves instances unchanged", func() { - Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(Equal(42))) + Expect(cfProcess.Spec.DesiredInstances).To(gstruct.PointTo(BeEquivalentTo(42))) }) }) }) diff --git a/controllers/api/v1alpha1/cfroute_types.go b/controllers/api/v1alpha1/cfroute_types.go index 06c3927df..e54dfeab2 100644 --- a/controllers/api/v1alpha1/cfroute_types.go +++ b/controllers/api/v1alpha1/cfroute_types.go @@ -37,7 +37,7 @@ type Destination struct { // either the droplet port, or 8080 if no ports are available in the // droplet //+kubebuilder:validation:Optional - Port *int `json:"port,omitempty"` + Port *int32 `json:"port,omitempty"` // A required reference to the CFApp that will receive traffic. The CFApp must be in the same namespace AppRef v1.LocalObjectReference `json:"appRef"` // The process type on the CFApp app which will receive traffic diff --git a/controllers/api/v1alpha1/zz_generated.deepcopy.go b/controllers/api/v1alpha1/zz_generated.deepcopy.go index e9f1fb879..940e2c12d 100644 --- a/controllers/api/v1alpha1/zz_generated.deepcopy.go +++ b/controllers/api/v1alpha1/zz_generated.deepcopy.go @@ -1023,7 +1023,7 @@ func (in *CFProcessSpec) DeepCopyInto(out *CFProcessSpec) { out.HealthCheck = in.HealthCheck if in.DesiredInstances != nil { in, out := &in.DesiredInstances, &out.DesiredInstances - *out = new(int) + *out = new(int32) **out = **in } if in.Ports != nil { @@ -1834,7 +1834,7 @@ func (in *Destination) DeepCopyInto(out *Destination) { *out = *in if in.Port != nil { in, out := &in.Port, &out.Port - *out = new(int) + *out = new(int32) **out = **in } out.AppRef = in.AppRef diff --git a/controllers/config/config.go b/controllers/config/config.go index 5771edcfc..f0877635d 100644 --- a/controllers/config/config.go +++ b/controllers/config/config.go @@ -27,7 +27,7 @@ type ControllerConfig struct { MaxRetainedPackagesPerApp int `yaml:"maxRetainedPackagesPerApp"` MaxRetainedBuildsPerApp int `yaml:"maxRetainedBuildsPerApp"` LogLevel zapcore.Level `yaml:"logLevel"` - SpaceFinalizerAppDeletionTimeout *int64 `yaml:"spaceFinalizerAppDeletionTimeout"` + SpaceFinalizerAppDeletionTimeout *int32 `yaml:"spaceFinalizerAppDeletionTimeout"` // job-task-runner JobTTL string `yaml:"jobTTL"` @@ -51,7 +51,7 @@ type ControllerConfig struct { type CFProcessDefaults struct { MemoryMB int64 `yaml:"memoryMB"` DiskQuotaMB int64 `yaml:"diskQuotaMB"` - Timeout *int64 `yaml:"timeout"` + Timeout *int32 `yaml:"timeout"` } type CFStagingResources struct { @@ -67,7 +67,7 @@ type Networking struct { const ( defaultTaskTTL = 30 * 24 * time.Hour - defaultTimeout int64 = 60 + defaultTimeout int32 = 60 defaultJobTTL = 24 * time.Hour defaultBuildCacheMB = 2048 ) diff --git a/controllers/config/config_test.go b/controllers/config/config_test.go index bb1db2a4c..5a9c2c139 100644 --- a/controllers/config/config_test.go +++ b/controllers/config/config_test.go @@ -33,7 +33,7 @@ var _ = Describe("LoadFromPath", func() { CFProcessDefaults: config.CFProcessDefaults{ MemoryMB: 1024, DiskQuotaMB: 512, - Timeout: tools.PtrTo(int64(30)), + Timeout: tools.PtrTo(int32(30)), }, CFStagingResources: config.CFStagingResources{ BuildCacheMB: 1024, @@ -47,7 +47,7 @@ var _ = Describe("LoadFromPath", func() { RunnerName: "statefulset-runner", JobTTL: "jobTTL", LogLevel: zapcore.DebugLevel, - SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int64(42)), + SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int32(42)), Networking: config.Networking{ GatewayName: "gw-name", GatewayNamespace: "gw-ns", @@ -75,7 +75,7 @@ var _ = Describe("LoadFromPath", func() { CFProcessDefaults: config.CFProcessDefaults{ MemoryMB: 1024, DiskQuotaMB: 512, - Timeout: tools.PtrTo(int64(30)), + Timeout: tools.PtrTo(int32(30)), }, CFStagingResources: config.CFStagingResources{ BuildCacheMB: 1024, @@ -91,7 +91,7 @@ var _ = Describe("LoadFromPath", func() { ExtraVCAPApplicationValues: map[string]any{}, JobTTL: "jobTTL", LogLevel: zapcore.DebugLevel, - SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int64(42)), + SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int32(42)), Networking: config.Networking{ GatewayName: "gw-name", GatewayNamespace: "gw-ns", @@ -107,7 +107,7 @@ var _ = Describe("LoadFromPath", func() { }) It("uses the default", func() { - Expect(retConfig.CFProcessDefaults.Timeout).To(gstruct.PointTo(Equal(int64(60)))) + Expect(retConfig.CFProcessDefaults.Timeout).To(gstruct.PointTo(BeEquivalentTo(60))) }) }) @@ -127,7 +127,7 @@ var _ = Describe("LoadFromPath", func() { }) It("uses the default", func() { - Expect(retConfig.SpaceFinalizerAppDeletionTimeout).To(gstruct.PointTo(Equal(int64(60)))) + Expect(retConfig.SpaceFinalizerAppDeletionTimeout).To(gstruct.PointTo(BeEquivalentTo(60))) }) }) diff --git a/controllers/controllers/networking/routes/controller.go b/controllers/controllers/networking/routes/controller.go index 0c438a704..1714283a1 100644 --- a/controllers/controllers/networking/routes/controller.go +++ b/controllers/controllers/networking/routes/controller.go @@ -246,9 +246,9 @@ func (r *Reconciler) buildEffectiveDestinations(ctx context.Context, cfRoute *ko continue } - effectiveDest.Port = tools.PtrTo(8080) + effectiveDest.Port = tools.PtrTo[int32](8080) if len(droplet.Ports) > 0 { - effectiveDest.Port = tools.PtrTo(int(droplet.Ports[0])) + effectiveDest.Port = tools.PtrTo(droplet.Ports[0]) } } diff --git a/controllers/controllers/networking/routes/controller_test.go b/controllers/controllers/networking/routes/controller_test.go index 728a24a07..a3d4573a3 100644 --- a/controllers/controllers/networking/routes/controller_test.go +++ b/controllers/controllers/networking/routes/controller_test.go @@ -133,7 +133,7 @@ var _ = Describe("CFRouteReconciler Integration Tests", func() { Name: cfApp.Name, }, ProcessType: "web", - Port: tools.PtrTo(80), + Port: tools.PtrTo[int32](80), }, } }) @@ -238,7 +238,7 @@ var _ = Describe("CFRouteReconciler Integration Tests", func() { g.Expect(adminClient.Get(ctx, client.ObjectKeyFromObject(cfRoute), cfRoute)).To(Succeed()) g.Expect(cfRoute.Status.Destinations).To(ConsistOf(korifiv1alpha1.Destination{ GUID: cfRoute.Spec.Destinations[0].GUID, - Port: tools.PtrTo(80), + Port: tools.PtrTo[int32](80), Protocol: tools.PtrTo("http1"), AppRef: cfRoute.Spec.Destinations[0].AppRef, ProcessType: "web", diff --git a/controllers/controllers/workloads/env/builder_test.go b/controllers/controllers/workloads/env/builder_test.go index efb09f580..f66cf2f5d 100644 --- a/controllers/controllers/workloads/env/builder_test.go +++ b/controllers/controllers/workloads/env/builder_test.go @@ -316,7 +316,7 @@ var _ = Describe("EnvBuilder", func() { BeforeEach(func() { destinations := []korifiv1alpha1.Destination{{ GUID: "dest-guid", - Port: tools.PtrTo(1234), + Port: tools.PtrTo[int32](1234), AppRef: corev1.LocalObjectReference{ Name: cfApp.Name, }, diff --git a/controllers/controllers/workloads/k8sns/space_apps_finalizer.go b/controllers/controllers/workloads/k8sns/space_apps_finalizer.go index fd56bf752..dbac798e7 100644 --- a/controllers/controllers/workloads/k8sns/space_apps_finalizer.go +++ b/controllers/controllers/workloads/k8sns/space_apps_finalizer.go @@ -17,12 +17,12 @@ import ( type SpaceAppsFinalizer struct { client client.Client - appDeletionTimeout int64 + appDeletionTimeout int32 } func NewSpaceAppsFinalizer( client client.Client, - appDeletionTimeout int64, + appDeletionTimeout int32, ) *SpaceAppsFinalizer { return &SpaceAppsFinalizer{ client: client, diff --git a/controllers/controllers/workloads/ports/ports_test.go b/controllers/controllers/workloads/ports/ports_test.go index 355247574..08004a9c0 100644 --- a/controllers/controllers/workloads/ports/ports_test.go +++ b/controllers/controllers/workloads/ports/ports_test.go @@ -26,7 +26,7 @@ var _ = Describe("FromRoutes", func() { Status: korifiv1alpha1.CFRouteStatus{ Destinations: []korifiv1alpha1.Destination{{ GUID: "dest-guid", - Port: tools.PtrTo(9876), + Port: tools.PtrTo[int32](9876), AppRef: corev1.LocalObjectReference{ Name: "my-app", }, @@ -53,7 +53,7 @@ var _ = Describe("FromRoutes", func() { Status: korifiv1alpha1.CFRouteStatus{ Destinations: []korifiv1alpha1.Destination{{ GUID: "dest-guid", - Port: tools.PtrTo(1234), + Port: tools.PtrTo[int32](1234), AppRef: corev1.LocalObjectReference{ Name: "my-app", }, diff --git a/controllers/controllers/workloads/processes/controller_test.go b/controllers/controllers/workloads/processes/controller_test.go index 422a134e1..542060f3b 100644 --- a/controllers/controllers/workloads/processes/controller_test.go +++ b/controllers/controllers/workloads/processes/controller_test.go @@ -97,7 +97,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() { GUID: uuid.NewString(), AppRef: corev1.LocalObjectReference{Name: cfApp.Name}, ProcessType: korifiv1alpha1.ProcessTypeWeb, - Port: tools.PtrTo(8080), + Port: tools.PtrTo[int32](8080), Protocol: tools.PtrTo("http1"), }}, }, @@ -149,7 +149,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() { ProcessType: korifiv1alpha1.ProcessTypeWeb, Command: "process command", DetectedCommand: "detected-command", - DesiredInstances: tools.PtrTo(1), + DesiredInstances: tools.PtrTo[int32](1), MemoryMB: 1024, DiskQuotaMB: 100, }, @@ -390,7 +390,7 @@ var _ = Describe("CFProcessReconciler Integration Tests", func() { JustBeforeEach(func() { eventuallyCreatedAppWorkloadShould(func(g Gomega, appWorkload korifiv1alpha1.AppWorkload) {}) Expect(k8s.Patch(ctx, adminClient, cfProcess, func() { - cfProcess.Spec.DesiredInstances = tools.PtrTo(0) + cfProcess.Spec.DesiredInstances = tools.PtrTo[int32](0) })).To(Succeed()) }) diff --git a/controllers/controllers/workloads/spaces/controller.go b/controllers/controllers/workloads/spaces/controller.go index 8305f7c30..335d3ad48 100644 --- a/controllers/controllers/workloads/spaces/controller.go +++ b/controllers/controllers/workloads/spaces/controller.go @@ -44,7 +44,7 @@ type Reconciler struct { namespaceReconciler *k8sns.Reconciler[korifiv1alpha1.CFSpace, *korifiv1alpha1.CFSpace] containerRegistrySecretNames []string rootNamespace string - appDeletionTimeout int64 + appDeletionTimeout int32 } func NewReconciler( @@ -52,7 +52,7 @@ func NewReconciler( log logr.Logger, containerRegistrySecretNames []string, rootNamespace string, - appDeletionTimeout int64, + appDeletionTimeout int32, labelCompiler labels.Compiler, ) *k8s.PatchingReconciler[korifiv1alpha1.CFSpace, *korifiv1alpha1.CFSpace] { namespaceController := k8sns.NewReconciler[korifiv1alpha1.CFSpace, *korifiv1alpha1.CFSpace]( diff --git a/controllers/controllers/workloads/spaces/suite_test.go b/controllers/controllers/workloads/spaces/suite_test.go index 2c0f515ef..b13848e7f 100644 --- a/controllers/controllers/workloads/spaces/suite_test.go +++ b/controllers/controllers/workloads/spaces/suite_test.go @@ -89,7 +89,7 @@ var _ = BeforeSuite(func() { ctrl.Log.WithName("controllers").WithName("CFSpace"), []string{packageRegistrySecretName}, cfRootNamespace, - int64(2), + int32(2), labelCompiler, ).SetupWithManager(k8sManager) Expect(err).NotTo(HaveOccurred()) diff --git a/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfprocesses.yaml b/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfprocesses.yaml index d1586abbf..22247d169 100644 --- a/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfprocesses.yaml +++ b/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfprocesses.yaml @@ -60,6 +60,7 @@ spec: type: string desiredInstances: description: The desired number of replicas to deploy + format: int32 type: integer detectedCommand: description: The default command for this process as defined by the @@ -81,10 +82,10 @@ spec: description: The http endpoint to use with "http" healthchecks type: string invocationTimeoutSeconds: - format: int64 + format: int32 type: integer timeoutSeconds: - format: int64 + format: int32 type: integer required: - invocationTimeoutSeconds diff --git a/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfroutes.yaml b/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfroutes.yaml index 284ab0fc4..f5d7573af 100644 --- a/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfroutes.yaml +++ b/helm/korifi/controllers/crds/korifi.cloudfoundry.org_cfroutes.yaml @@ -77,6 +77,7 @@ spec: The port to use for the destination. Port is optional, and defaults to either the droplet port, or 8080 if no ports are available in the droplet + format: int32 type: integer processType: description: The process type on the CFApp app which will receive @@ -245,6 +246,7 @@ spec: The port to use for the destination. Port is optional, and defaults to either the droplet port, or 8080 if no ports are available in the droplet + format: int32 type: integer processType: description: The process type on the CFApp app which will receive diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh index 580a8f87f..b62098d77 100755 --- a/scripts/run-tests.sh +++ b/scripts/run-tests.sh @@ -94,6 +94,10 @@ function run_ginkgo() { extra_args+=("-p") fi + if [[ -z "${KEEP_GOING:-}" ]]; then + extra_args+=("--keep-going") + fi + go run github.com/onsi/ginkgo/v2/ginkgo --output-interceptor-mode=none --randomize-all --randomize-suites "${extra_args[@]}" $@ } diff --git a/tools/image/client.go b/tools/image/client.go index 2d57974f5..2636e6163 100644 --- a/tools/image/client.go +++ b/tools/image/client.go @@ -133,7 +133,7 @@ func (c Client) Config(ctx context.Context, creds Creds, imageRef string) (Confi if err != nil { return Config{}, fmt.Errorf("error getting exposed ports: %w", err) } - ports = append(ports, int32(parsed)) + ports = append(ports, int32(parsed)) // #nosec G115 } return Config{