-
Notifications
You must be signed in to change notification settings - Fork 153
/
flux.go
59 lines (46 loc) · 1.33 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
package flux
import (
"fmt"
"github.com/weaveworks/weave-gitops/pkg/gitproviders"
"github.com/weaveworks/weave-gitops/pkg/runner"
)
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate
//counterfeiter:generate . Flux
type Flux interface {
CreateSecretGit(name string, repoUrl gitproviders.RepoURL, namespace string) ([]byte, error)
}
const (
PartOfLabelKey = "app.kubernetes.io/part-of"
PartOfLabelValue = "flux"
VersionLabelKey = "app.kubernetes.io/version"
)
type FluxClient struct {
runner runner.Runner
}
func New(cliRunner runner.Runner) *FluxClient {
return &FluxClient{
runner: cliRunner,
}
}
var _ Flux = &FluxClient{}
// CreatSecretGit Creates a Git secret returns the deploy key
func (f *FluxClient) CreateSecretGit(name string, repoUrl gitproviders.RepoURL, namespace string) ([]byte, error) {
args := []string{
"create", "secret", "git", name,
"--url", repoUrl.String(),
"--namespace", namespace,
"--export",
}
out, err := f.runFluxCmd(args...)
if err != nil {
return out, fmt.Errorf("failed to create secret git: %w", err)
}
return out, nil
}
func (f *FluxClient) runFluxCmd(args ...string) ([]byte, error) {
out, err := f.runner.Run("flux", args...)
if err != nil {
return []byte{}, fmt.Errorf("failed to run flux with output: %s and error: %w", string(out), err)
}
return out, nil
}