forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncer.go
69 lines (52 loc) · 2.2 KB
/
syncer.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
package linkerd
import (
"context"
"k8s.io/client-go/kubernetes"
"github.com/solo-io/go-utils/contextutils"
"github.com/solo-io/go-utils/errors"
"github.com/solo-io/supergloo/pkg/install/common"
"github.com/solo-io/supergloo/pkg/util"
"github.com/solo-io/go-utils/installutils/kubeinstall"
"github.com/solo-io/solo-kit/pkg/api/v1/reporter"
v1 "github.com/solo-io/supergloo/pkg/api/v1"
)
// calling this function with nil is valid and expected outside of tests
func NewInstallSyncer(kubeInstaller kubeinstall.Installer, kubeClient kubernetes.Interface, meshClient v1.MeshClient, reporter reporter.Reporter) v1.InstallSyncer {
return common.NewMeshInstallSyncer("linkerd", meshClient, reporter, isLinkerdInstall, linkerdInstaller{kubeInstaller: kubeInstaller, kubeClient: kubeClient}.ensureLinkerdInstall)
}
func isLinkerdInstall(install *v1.Install) bool {
mesh := install.GetMesh()
if mesh == nil {
return false
}
return mesh.GetLinkerd() != nil
}
type linkerdInstaller struct {
kubeInstaller kubeinstall.Installer
kubeClient kubernetes.Interface
}
func (i linkerdInstaller) ensureLinkerdInstall(ctx context.Context, install *v1.Install, meshes v1.MeshList) error {
installMesh := install.GetMesh()
if installMesh == nil {
return errors.Errorf("%v: invalid install type, must be a mesh", install.Metadata.Ref())
}
linkerd := installMesh.GetLinkerd()
if linkerd == nil {
return errors.Errorf("%v: invalid install type, only linkerd supported currently", install.Metadata.Ref())
}
logger := contextutils.LoggerFrom(ctx)
logger.Infof("syncing linkerd install %v with config %v", install.Metadata.Ref().Key(), linkerd)
installLabels := util.LabelsForResource(install)
if install.Disabled {
logger.Infof("purging resources for disabled install %v", install.Metadata.Ref())
if err := i.kubeInstaller.PurgeResources(ctx, installLabels); err != nil {
return errors.Wrapf(err, "uninstalling linkerd")
}
return nil
}
opts := newInstallOpts(linkerd.Version, install.InstallationNamespace, linkerd.EnableMtls, linkerd.EnableAutoInject)
if err := opts.install(ctx, i.kubeInstaller, installLabels, i.kubeClient); err != nil {
return errors.Wrapf(err, "executing linkerd install")
}
return nil
}