-
Notifications
You must be signed in to change notification settings - Fork 104
/
exists_change.go
45 lines (35 loc) · 1013 Bytes
/
exists_change.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
// Copyright 2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package clusterapply
import (
"fmt"
ctldiff "github.com/k14s/kapp/pkg/kapp/diff"
ctlres "github.com/k14s/kapp/pkg/kapp/resources"
)
type ExistsChange struct {
change ctldiff.Change
identifiedResources ctlres.IdentifiedResources
}
func (c ExistsChange) ApplyStrategy() (ApplyStrategy, error) {
res := c.change.NewResource()
return ExistsStrategy{res, c.identifiedResources}, nil
}
type ExistsStrategy struct {
res ctlres.Resource
identifiedResources ctlres.IdentifiedResources
}
func (e ExistsStrategy) Op() ClusterChangeApplyStrategyOp { return "" }
func (e ExistsStrategy) Apply() error {
_, exists, err := e.identifiedResources.Exists(e.res, ctlres.ExistsOpts{})
if !exists {
if err != nil {
return err
}
return ExistsChangeError{}
}
return nil
}
type ExistsChangeError struct{}
func (e ExistsChangeError) Error() string {
return fmt.Sprint("External resource doesn't exists")
}