Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/preview/previewctl/pkg/k8s/vm.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package k8s
6
7
import (
8
"context"
9
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
"k8s.io/apimachinery/pkg/runtime/schema"
12
)
13
14
var (
15
vmResource = schema.GroupVersionResource{
16
Group: "kubevirt.io",
17
Version: "v1",
18
Resource: "virtualmachines",
19
}
20
)
21
22
func (c *Config) GetSVCCreationTimestamp(ctx context.Context, name, namespace string) (*metav1.Time, error) {
23
svc, err := c.CoreClient.CoreV1().Services(namespace).Get(ctx, "proxy", metav1.GetOptions{})
24
if err != nil {
25
return nil, err
26
}
27
28
return &svc.ObjectMeta.CreationTimestamp, nil
29
}
30
31
func (c *Config) GetVMs(ctx context.Context) ([]string, error) {
32
virtualMachineClient := c.DynamicClient.Resource(vmResource).Namespace("")
33
vmObjs, err := virtualMachineClient.List(ctx, metav1.ListOptions{})
34
if err != nil {
35
return nil, err
36
}
37
38
var vms []string
39
for _, item := range vmObjs.Items {
40
vms = append(vms, item.GetName())
41
}
42
43
return vms, nil
44
}
45
46