forked from kyma-project/kyma
/
assetgroup.go
84 lines (72 loc) · 2.13 KB
/
assetgroup.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package rafter
import (
"github.com/kyma-project/kyma/tests/end-to-end/upgrade/pkg/dynamicresource"
"github.com/kyma-project/kyma/tests/end-to-end/upgrade/pkg/waiter"
"github.com/kyma-project/rafter/pkg/apis/rafter/v1beta1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
)
type assetGroup struct {
resCli *dynamicresource.DynamicResource
name string
namespace string
spec v1beta1.CommonAssetGroupSpec
}
func newAssetGroup(dynamicCli dynamic.Interface, namespace string, spec v1beta1.CommonAssetGroupSpec) *assetGroup {
return &assetGroup{
resCli: dynamicresource.NewClient(dynamicCli, schema.GroupVersionResource{
Version: v1beta1.GroupVersion.Version,
Group: v1beta1.GroupVersion.Group,
Resource: "assetgroups",
}),
namespace: namespace,
name: assetGroupName,
spec: spec,
}
}
func (ag *assetGroup) create() error {
assetGroup := &v1beta1.AssetGroup{
TypeMeta: metav1.TypeMeta{
Kind: "AssetGroup",
APIVersion: v1beta1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: ag.name,
Namespace: ag.namespace,
},
Spec: v1beta1.AssetGroupSpec{
CommonAssetGroupSpec: ag.spec,
},
}
err := ag.resCli.Create(assetGroup)
if err != nil {
return errors.Wrapf(err, "while creating AssetGroup %s in namespace %s", ag.name, ag.namespace)
}
return nil
}
func (ag *assetGroup) get() (*v1beta1.AssetGroup, error) {
var res v1beta1.AssetGroup
err := ag.resCli.Get(ag.namespace, ag.name, &res)
if err != nil {
return nil, errors.Wrapf(err, "while converting AssetGroup %s in namespace %s", ag.name, ag.namespace)
}
return &res, nil
}
func (ag *assetGroup) waitForStatusReady(stop <-chan struct{}) error {
err := waiter.WaitAtMost(func() (bool, error) {
res, err := ag.get()
if err != nil {
return false, err
}
if res.Status.Phase != v1beta1.AssetGroupReady {
return false, nil
}
return true, nil
}, waitTimeout, stop)
if err != nil {
return errors.Wrapf(err, "while waiting for ready AssetGroup %s in namespace %s", ag.name, ag.namespace)
}
return nil
}