-
Notifications
You must be signed in to change notification settings - Fork 275
/
flux.go
112 lines (92 loc) 路 2.57 KB
/
flux.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package api
import (
"os"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
)
type FluxConfigOpt func(o *v1alpha1.FluxConfig)
func NewFluxConfig(name string, opts ...FluxConfigOpt) *v1alpha1.FluxConfig {
config := &v1alpha1.FluxConfig{
TypeMeta: metav1.TypeMeta{
APIVersion: v1alpha1.SchemeBuilder.GroupVersion.String(),
Kind: v1alpha1.FluxConfigKind,
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1alpha1.FluxConfigSpec{},
}
for _, opt := range opts {
opt(config)
}
return config
}
func WithFluxConfigNamespace(ns string) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
c.Namespace = ns
}
}
func WithBranch(branch string) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
c.Spec.Branch = branch
}
}
func WithClusterConfigPath(configPath string) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
c.Spec.ClusterConfigPath = configPath
}
}
func WithSystemNamespace(namespace string) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
c.Spec.SystemNamespace = namespace
}
}
func WithStringFromEnvVarFluxConfig(envVar string, opt func(string) FluxConfigOpt) FluxConfigOpt {
return opt(os.Getenv(envVar))
}
type GitProviderOpt func(o *v1alpha1.GitProviderConfig)
func WithGenericGitProvider(opts ...GitProviderOpt) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
g := &v1alpha1.GitProviderConfig{}
for _, opt := range opts {
opt(g)
}
c.Spec.Git = g
}
}
func WithGitRepositoryUrl(url string) GitProviderOpt {
return func(c *v1alpha1.GitProviderConfig) {
c.RepositoryUrl = url
}
}
func WithStringFromEnvVarGenericGitProviderConfig(envVar string, opt func(string) GitProviderOpt) GitProviderOpt {
return opt(os.Getenv(envVar))
}
type GithubProviderOpt func(o *v1alpha1.GithubProviderConfig)
func WithGithubProvider(opts ...GithubProviderOpt) FluxConfigOpt {
return func(c *v1alpha1.FluxConfig) {
g := &v1alpha1.GithubProviderConfig{}
for _, opt := range opts {
opt(g)
}
c.Spec.Github = g
}
}
func WithGithubOwner(owner string) GithubProviderOpt {
return func(c *v1alpha1.GithubProviderConfig) {
c.Owner = owner
}
}
func WithGithubRepository(repository string) GithubProviderOpt {
return func(c *v1alpha1.GithubProviderConfig) {
c.Repository = repository
}
}
func WithPersonalGithubRepository(personal bool) GithubProviderOpt {
return func(c *v1alpha1.GithubProviderConfig) {
c.Personal = personal
}
}
func WithStringFromEnvVarGithubProviderConfig(envVar string, opt func(string) GithubProviderOpt) GithubProviderOpt {
return opt(os.Getenv(envVar))
}