File: client.go

package info (click to toggle)
golang-github-crc-org-crc 2.34.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,548 kB
  • sloc: sh: 398; makefile: 326; javascript: 40
file content (128 lines) | stat: -rw-r--r-- 2,789 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package fakemachine

import (
	"context"
	"errors"

	"github.com/crc-org/crc/v2/pkg/crc/machine/state"
	"github.com/crc-org/crc/v2/pkg/crc/machine/types"
	"github.com/crc-org/crc/v2/pkg/crc/network/httpproxy"
	"github.com/crc-org/crc/v2/pkg/crc/preset"
)

func NewClient() *Client {
	return &Client{}
}

func NewFailingClient() *Client {
	return &Client{
		Failing: true,
	}
}

type Client struct {
	Failing bool
}

var DummyClusterConfig = types.ClusterConfig{
	ClusterType:   "openshift",
	ClusterCACert: "MIIDODCCAiCgAwIBAgIIRVfCKNUa1wIwDQYJ",
	KubeConfig:    "/tmp/kubeconfig",
	KubeAdminPass: "foobar",
	ClusterAPI:    "https://foo.testing:6443",
	WebConsoleURL: "https://console.foo.testing:6443",
	ProxyConfig:   nil,
}

func (c *Client) GetName() string {
	return "crc"
}

func (c *Client) Delete() error {
	if c.Failing {
		return errors.New("delete failed")
	}
	return nil
}

func (c *Client) GetConsoleURL() (*types.ConsoleResult, error) {
	if c.Failing {
		return nil, errors.New("console failed")
	}
	return &types.ConsoleResult{
		ClusterConfig: DummyClusterConfig,
		State:         state.Running,
	}, nil
}

func (c *Client) GetProxyConfig(_ string) (*httpproxy.ProxyConfig, error) {
	return nil, errors.New("not implemented")
}

func (c *Client) ConnectionDetails() (*types.ConnectionDetails, error) {
	return nil, errors.New("not implemented")
}

func (c *Client) PowerOff() error {
	if c.Failing {
		return errors.New("poweroff failed")
	}
	return nil
}

func (c *Client) GenerateBundle(_ bool) error {
	if c.Failing {
		return errors.New("bundle generation failed")
	}
	return nil
}

func (c *Client) Start(_ context.Context, _ types.StartConfig) (*types.StartResult, error) {
	if c.Failing {
		return nil, errors.New("Failed to start")
	}
	return &types.StartResult{
		ClusterConfig:  DummyClusterConfig,
		KubeletStarted: true,
	}, nil
}

func (c *Client) Stop() (state.State, error) {
	if c.Failing {
		return state.Running, errors.New("stop failed")
	}
	return state.Stopped, nil
}

func (c *Client) Status() (*types.ClusterStatusResult, error) {
	if c.Failing {
		return nil, errors.New("broken")
	}
	return &types.ClusterStatusResult{
		CrcStatus:        state.Running,
		OpenshiftStatus:  types.OpenshiftRunning,
		OpenshiftVersion: "4.5.1",
		PodmanVersion:    "3.3.1",
		DiskUse:          10_000_000_000,
		DiskSize:         20_000_000_000,
		RAMSize:          2_000,
		RAMUse:           1_000,
		Preset:           preset.OpenShift,
	}, nil
}

func (c *Client) Exists() (bool, error) {
	return true, nil
}

func (c *Client) IsRunning() (bool, error) {
	return true, nil
}

func (c *Client) GetPreset() preset.Preset {
	return preset.OpenShift
}

func (c *Client) GetClusterLoad() (*types.ClusterLoadResult, error) {
	return nil, errors.New("not implemented")
}