-
Notifications
You must be signed in to change notification settings - Fork 104
/
instance.go
54 lines (45 loc) · 1.69 KB
/
instance.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
package install
import (
"errors"
"fmt"
"time"
pollwait "k8s.io/apimachinery/pkg/util/wait"
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1"
"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
)
// Instance installs a KUDO instance to a cluster.
// It returns an error if the namespace already contains an instance with the same name.
func Instance(client *kudo.Client, instance *v1beta1.Instance) error {
existingInstance, err := client.GetInstance(instance.Name, instance.Namespace)
if err != nil {
return fmt.Errorf("failed to verify existing instance: %v", err)
}
if existingInstance != nil {
return clog.Errorf(
"cannot install instance '%s' because an instance of that name already exists in namespace %s",
instance.Name,
instance.Namespace)
}
if _, err := client.InstallInstanceObjToCluster(instance, instance.Namespace); err != nil {
return fmt.Errorf(
"failed to install instance %s/%s: %v",
instance.Namespace,
instance.Name,
err)
}
clog.Printf("instance %s/%s created", instance.Namespace, instance.Name)
return nil
}
// WaitForInstance waits for an amount of time for an instance to be "complete".
func WaitForInstance(client *kudo.Client, instance *v1beta1.Instance, timeout time.Duration) error {
err := client.WaitForInstance(instance.Name, instance.Namespace, nil, timeout)
if errors.Is(err, pollwait.ErrWaitTimeout) {
clog.Printf("timeout waiting for instance %s/%s", instance.Namespace, instance.Name)
}
if err != nil {
return fmt.Errorf("failed to wait on instance %s/%s: %v", instance.Namespace, instance.Name, err)
}
clog.Printf("instance %s/%s ready", instance.Namespace, instance.Name)
return nil
}