-
Notifications
You must be signed in to change notification settings - Fork 282
/
gitopsconfig_types.go
144 lines (118 loc) Β· 3.61 KB
/
gitopsconfig_types.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GitOps defines the configurations of GitOps Toolkit and Git repository it links to.
type GitOpsConfigSpec struct {
Flux Flux `json:"flux,omitempty"`
}
// Flux defines the Git repository options for Flux v2.
type Flux struct {
// github is the name of the Git Provider to host the Git repo.
Github Github `json:"github,omitempty"`
}
type Github struct {
// Owner is the user or organization name of the Git provider.
Owner string `json:"owner"`
// Repository name.
Repository string `json:"repository"`
// FluxSystemNamespace scope for this operation. Defaults to flux-system.
FluxSystemNamespace string `json:"fluxSystemNamespace,omitempty"`
// Git branch. Defaults to main.
// +kubebuilder:default:="main"
Branch string `json:"branch,omitempty"`
// ClusterConfigPath relative to the repository root, when specified the cluster sync will be scoped to this path.
ClusterConfigPath string `json:"clusterConfigPath,omitempty"`
// if true, the owner is assumed to be a Git user; otherwise an org.
Personal bool `json:"personal,omitempty"`
}
// GitOpsConfigStatus defines the observed state of GitOpsConfig.
type GitOpsConfigStatus struct{}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
type GitOpsConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec GitOpsConfigSpec `json:"spec,omitempty"`
Status GitOpsConfigStatus `json:"status,omitempty"`
}
// +kubebuilder:object:generate=false
// Same as GitOpsConfig except stripped down for generation of yaml file while writing to github repo when flux is enabled.
type GitOpsConfigGenerate struct {
metav1.TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
Spec GitOpsConfigSpec `json:"spec,omitempty"`
}
func (e *GitOpsConfigSpec) Equal(n *GitOpsConfigSpec) bool {
if e == n {
return true
}
if e == nil || n == nil {
return false
}
return e.Flux == n.Flux
}
//+kubebuilder:object:root=true
// GitOpsConfigList contains a list of GitOpsConfig.
type GitOpsConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitOpsConfig `json:"items"`
}
func (c *GitOpsConfig) Kind() string {
return c.TypeMeta.Kind
}
func (c *GitOpsConfig) ExpectedKind() string {
return GitOpsConfigKind
}
func (c *GitOpsConfig) ConvertToFluxConfig() *FluxConfig {
if c == nil {
return nil
}
config := &FluxConfig{
TypeMeta: metav1.TypeMeta{
Kind: FluxConfigKind,
APIVersion: c.APIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: c.Name,
Namespace: c.Namespace,
},
Spec: FluxConfigSpec{
SystemNamespace: c.Spec.Flux.Github.FluxSystemNamespace,
Branch: c.Spec.Flux.Github.Branch,
ClusterConfigPath: c.Spec.Flux.Github.ClusterConfigPath,
Github: &GithubProviderConfig{
Owner: c.Spec.Flux.Github.Owner,
Repository: c.Spec.Flux.Github.Repository,
Personal: c.Spec.Flux.Github.Personal,
},
},
}
return config
}
func (c *GitOpsConfig) ConvertConfigToConfigGenerateStruct() *GitOpsConfigGenerate {
namespace := defaultEksaNamespace
if c.Namespace != "" {
namespace = c.Namespace
}
config := &GitOpsConfigGenerate{
TypeMeta: c.TypeMeta,
ObjectMeta: ObjectMeta{
Name: c.Name,
Annotations: c.Annotations,
Namespace: namespace,
},
Spec: c.Spec,
}
return config
}
func (c *GitOpsConfig) Validate() error {
return validateGitOpsConfig(c)
}
func (c *GitOpsConfig) SetDefaults() {
setGitOpsConfigDefaults(c)
}
func init() {
SchemeBuilder.Register(&GitOpsConfig{}, &GitOpsConfigList{})
}