/
util.go
46 lines (38 loc) · 925 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package util
import (
"fmt"
"strings"
claimv1alpha1 "github.com/tmax-cloud/tfc-operator/api/v1alpha1"
ctrl "sigs.k8s.io/controller-runtime"
)
// LowestNonZeroResult compares two reconciliation results
// and returns the one with lowest requeue time.
func LowestNonZeroResult(i, j ctrl.Result) ctrl.Result {
switch {
case i.IsZero():
return j
case j.IsZero():
return i
case i.Requeue:
return i
case j.Requeue:
return j
case i.RequeueAfter < j.RequeueAfter:
return i
default:
return j
}
}
func GetTerraformVariables(tfapply *claimv1alpha1.TFApplyClaim) string {
// 변수 입력 확인 프롬프트 때문에 지연되는 것을 방지
cmd := " --input=false "
if tfapply.Spec.Variable == "" {
return cmd
}
variableList := strings.Split(tfapply.Spec.Variable, ",")
for _, v := range variableList {
value := strings.Trim(v, " ")
cmd += fmt.Sprintf("-var=%s ", value)
}
return cmd
}