This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathyamls.go
89 lines (75 loc) · 2 KB
/
yamls.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
85
86
87
88
89
/*
Copyright 2020 Intel Corporation.
SPDX-License-Identifier: Apache-2.0
*/
package deploy
import (
"embed"
"fmt"
"path"
"regexp"
api "github.com/intel/pmem-csi/pkg/apis/pmemcsi/v1beta1"
"github.com/intel/pmem-csi/pkg/version"
)
//go:embed kubernetes-*/*/pmem-csi.yaml
//go:embed kustomize/webhook/webhook.yaml
//go:embed kustomize/scheduler/scheduler-service.yaml
//go:embed kustomize/webhook/webhook-service.yaml
var assets embed.FS
// YamlFile contains all objects of a certain deployment.
type YamlFile struct {
// Name is the unique string which identifies the deployment.
Name string
// Kubernetes is the <major>.<minor> version the deployment
// was written for.
Kubernetes version.Version
// Flavor is a variant of the normal deployment for the Kubernetes version.
// Empty or a string leading with a hyphen.
Flavor string
// DeviceMode defines in which mode the deployed driver will
// operate.
DeviceMode api.DeviceMode
}
var yamls []YamlFile
var re = regexp.MustCompile(`^kubernetes-([0-9\.]*)([^/]*)/([^/]*)$`)
func init() {
deployDir, err := assets.ReadDir(".")
if err != nil {
panic(err)
}
for _, item := range deployDir {
if !item.IsDir() {
continue
}
kubernetesDir, err := assets.ReadDir(item.Name())
if err != nil {
panic(err)
}
for _, item2 := range kubernetesDir {
name := path.Join(item.Name(), item2.Name())
parts := re.FindStringSubmatch(name)
if parts == nil {
continue
}
kubernetes, err := version.Parse(parts[1])
if err != nil {
panic(fmt.Sprintf("unexpected version in %s: %v", name, err))
}
yamls = append(yamls, YamlFile{
Name: name,
Kubernetes: kubernetes,
Flavor: parts[3],
DeviceMode: api.DeviceMode(parts[3]),
})
}
}
}
// ListAll returns information about all embedded YAML files.
func ListAll() []YamlFile {
return yamls
}
// Asset returns the content of an embedded file.
// The path must be relative to the "deploy" dir.
func Asset(path string) ([]byte, error) {
return assets.ReadFile(path)
}