Skip to content

Commit d27b147

Browse files
authored
fix: Always use the correct casing for the 'kind' field (#88)
1 parent 6054852 commit d27b147

4 files changed

Lines changed: 52 additions & 10 deletions

File tree

internal/util/argParser.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package util
33
import (
44
"fmt"
55
"strings"
6-
7-
"golang.org/x/exp/slices"
86
)
97

108
type Input struct {
@@ -100,14 +98,20 @@ func CheckForMissingValues(arguments []string) error {
10098

10199
return nil
102100
}
103-
func FilterServiceKind(input []Input) (string, error) {
104-
serviceKindIndex := slices.IndexFunc(input, func(input Input) bool {
105-
return input.ParameterHierarchy[0] == K8S_SERVICE_KIND
106-
})
107-
if serviceKindIndex == -1 {
108-
return "", fmt.Errorf("ServiceKind is missing")
101+
func FilterServiceKind(input []Input) (string, []Input, error) {
102+
others := []Input{}
103+
kind := ""
104+
for _, input := range input {
105+
if input.ParameterHierarchy[0] == K8S_SERVICE_KIND {
106+
kind = input.Value
107+
} else {
108+
others = append(others, input)
109+
}
110+
}
111+
if kind == "" {
112+
return "", others, fmt.Errorf("ServiceKind is missing")
109113
} else {
110-
return input[serviceKindIndex].Value, nil
114+
return kind, others, nil
111115
}
112116
}
113117

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func Main(apps applications.AppMap, args []string, out io.Writer) int {
7373
return 1
7474
}
7575

76-
serviceKind, err := util.FilterServiceKind(parameters)
76+
serviceKind, parameters, err := util.FilterServiceKind(parameters)
7777
if err != nil {
7878
logrus.Errorf("%s", err)
7979
printUsage(args[0], apps)

tests/golden/vshnPostgreSQL.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"default": "postgres-default --kind VSHNPostgreSQL",
3+
"lowercase": "postgres-lowercase --kind vshnpostgresql",
34
"secret-ref": "postgres-secret-ref --kind VSHNPostgreSQL --spec.writeconnectionsecrettoref.name new-cred",
45
"parameters": "postgres-parameters --kind VSHNPostgreSQL --spec.parameters.backup.retention=9999 --spec.parameters.backup.schedule \"1 1 1 1 1\" --spec.parameters.size.CPU 100000m",
56
"unset": "postgres-unset --kind VSHNPostgreSQL --spec.parameters.size.disk- --spec.parameters.service- --spec.parameters.scheduling.nodeSelector-",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: vshn.appcat.vshn.io/v1
2+
kind: VSHNPostgreSQL
3+
metadata:
4+
creationTimestamp: null
5+
name: postgres-lowercase
6+
spec:
7+
parameters:
8+
backup:
9+
retention: 12
10+
schedule: 30 23 * * *
11+
encryption: {}
12+
maintenance: {}
13+
monitoring: {}
14+
network: {}
15+
replication: {}
16+
scheduling:
17+
nodeSelector:
18+
appuio.io/node-class: plus
19+
security: {}
20+
service:
21+
majorVersion: "14"
22+
pgSettings: null
23+
tls: {}
24+
size:
25+
cpu: 600m
26+
disk: 80Gi
27+
memory: 3500Mi
28+
requests:
29+
cpu: 300m
30+
memory: 1000Mi
31+
updateStrategy: {}
32+
writeConnectionSecretToRef:
33+
name: postgres-lowercase-creds
34+
namespace: ""
35+
status:
36+
schedules:
37+
maintenance: {}

0 commit comments

Comments
 (0)