-
Notifications
You must be signed in to change notification settings - Fork 32
/
prune.go
34 lines (27 loc) · 976 Bytes
/
prune.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
package commands
import (
"github.com/kluctl/kluctl/pkg/deployment"
utils2 "github.com/kluctl/kluctl/pkg/deployment/utils"
"github.com/kluctl/kluctl/pkg/k8s"
k8s2 "github.com/kluctl/kluctl/pkg/types/k8s"
)
type PruneCommand struct {
c *deployment.DeploymentCollection
}
func NewPruneCommand(c *deployment.DeploymentCollection) *PruneCommand {
return &PruneCommand{
c: c,
}
}
func (cmd *PruneCommand) Run(k *k8s.K8sCluster) ([]k8s2.ObjectRef, error) {
dew := utils2.NewDeploymentErrorsAndWarnings()
ru := utils2.NewRemoteObjectsUtil(dew)
err := ru.UpdateRemoteObjects(k, cmd.c.Project.GetCommonLabels(), nil)
if err != nil {
return nil, err
}
return FindOrphanObjects(k, ru, cmd.c)
}
func FindOrphanObjects(k *k8s.K8sCluster, ru *utils2.RemoteObjectUtils, c *deployment.DeploymentCollection) ([]k8s2.ObjectRef, error) {
return utils2.FindObjectsForDelete(k, ru.GetFilteredRemoteObjects(c.Inclusion), c.Inclusion.HasType("tags"), c.LocalObjectRefs())
}