-
Notifications
You must be signed in to change notification settings - Fork 273
/
gitops.go
74 lines (61 loc) 路 1.72 KB
/
gitops.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package api
import (
"os"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)
type GitOpsConfigOpt func(o *v1alpha1.GitOpsConfig)
func NewGitOpsConfig(name string, opts ...GitOpsConfigOpt) *v1alpha1.GitOpsConfig {
config := &v1alpha1.GitOpsConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha1.SchemeBuilder.GroupVersion.String(),
Kind: v1alpha1.GitOpsConfigKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1alpha1.GitOpsConfigSpec{},
}
for _, opt := range opts {
opt(config)
}
return config
}
func WithGitOpsNamespace(ns string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Namespace = ns
}
}
func WithFluxOwner(username string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.Owner = username
}
}
func WithFluxRepository(repository string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.Repository = repository
}
}
func WithFluxConfigurationPath(configPath string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.ClusterConfigPath = configPath
}
}
func WithFluxNamespace(namespace string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.FluxSystemNamespace = namespace
}
}
func WithFluxBranch(branch string) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.Branch = branch
}
}
func WithPersonalFluxRepository(personal bool) GitOpsConfigOpt {
return func(c *v1alpha1.GitOpsConfig) {
c.Spec.Flux.Github.Personal = personal
}
}
func WithStringFromEnvVarGitOpsConfig(envVar string, opt func(string) GitOpsConfigOpt) GitOpsConfigOpt {
return opt(os.Getenv(envVar))
}