-
Notifications
You must be signed in to change notification settings - Fork 1
/
unmanaged.go
37 lines (30 loc) · 1.36 KB
/
unmanaged.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
package kubernetes
import (
"github.com/pkg/errors"
nodeconfigv1 "github.com/atlarge-research/apate/pkg/apis/nodeconfiguration/v1"
podconfigv1 "github.com/atlarge-research/apate/pkg/apis/podconfiguration/v1"
"github.com/atlarge-research/apate/pkg/env"
"github.com/atlarge-research/apate/pkg/kubernetes/kubeconfig"
)
// UnmanagedClusterManager is a struct which implements ClusterManager by writing the given kubeconfig to a file.
type UnmanagedClusterManager struct{}
// GetKubeConfig writes the given kubeconfig and returns it as a struct.
func (u *UnmanagedClusterManager) GetKubeConfig() (*kubeconfig.KubeConfig, error) {
kubeConfig, err := kubeconfig.FromBytes([]byte(env.ControlPlaneEnv().KubeConfig), env.ControlPlaneEnv().KubeConfigLocation, true)
if err != nil {
return nil, errors.Wrap(err, "failed to create kube config from env variable")
}
return kubeConfig, nil
}
// Shutdown currently does nothing.
func (u *UnmanagedClusterManager) Shutdown(cluster *Cluster) error {
err := nodeconfigv1.UpdateInKubernetes(cluster.KubeConfig, true)
if err != nil {
return errors.Wrap(err, "failed to remove node CRD")
}
err = podconfigv1.UpdateInKubernetes(cluster.KubeConfig, true)
if err != nil {
return errors.Wrap(err, "failed to remove pod CRD")
}
return errors.Wrap(cluster.RemoveAllApateletsFromCluster(), "failed to remove all apatelets from cluster")
}