/
template.go
157 lines (148 loc) · 3.94 KB
/
template.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2024 Matrix Origin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package util
import (
"github.com/matrixorigin/matrixone-operator/api/core/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"time"
)
// NewLogSetTpl return a logSet template, name is random generated
func NewLogSetTpl(ns, image string) *v1alpha1.LogSet {
l := &v1alpha1.LogSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "log-" + rand.String(6),
},
Spec: v1alpha1.LogSetSpec{
PodSet: v1alpha1.PodSet{
Replicas: 3,
MainContainer: v1alpha1.MainContainer{
Image: image,
},
},
Volume: v1alpha1.Volume{
Size: resource.MustParse("100Mi"),
},
SharedStorage: v1alpha1.SharedStorageProvider{
FileSystem: &v1alpha1.FileSystemProvider{
Path: "/test",
},
},
StoreFailureTimeout: &metav1.Duration{Duration: 2 * time.Minute},
},
}
return l
}
// NewSecretTpl return a secret template, which namespace is ns, and name is random generated
func NewSecretTpl(ns string) *corev1.Secret {
sc := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: "secret-" + rand.String(6),
},
Data: map[string][]byte{},
}
return sc
}
// SecretVolume return a volume has a secret as volumeSource, volume name is same to secret volume
func SecretVolume(name string) corev1.Volume {
v := corev1.Volume{
Name: name,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: name,
},
},
}
return v
}
func MinioSecret(namespace string) *corev1.Secret {
minioSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "minio-" + rand.String(6),
},
StringData: map[string]string{
"AWS_ACCESS_KEY_ID": "minio",
"AWS_SECRET_ACCESS_KEY": "minio123",
},
}
return minioSecret
}
func MinioShareStorage(minioSecretName string) v1alpha1.SharedStorageProvider {
minioType := v1alpha1.S3ProviderTypeMinIO
SharedStorage := v1alpha1.SharedStorageProvider{
S3: &v1alpha1.S3Provider{
Path: "minio-bucket/test-" + rand.String(6),
Type: &minioType,
Endpoint: "http://minio.default:9000",
SecretRef: &corev1.LocalObjectReference{
Name: minioSecretName,
},
},
}
return SharedStorage
}
func NewMoTpl(namespace, version, repo string) *v1alpha1.MatrixOneCluster {
mo := &v1alpha1.MatrixOneCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: "mo-" + rand.String(6),
},
Spec: v1alpha1.MatrixOneClusterSpec{
TP: &v1alpha1.CNSetSpec{
PodSet: v1alpha1.PodSet{
Replicas: 2,
},
ConfigThatChangeCNSpec: v1alpha1.ConfigThatChangeCNSpec{
CacheVolume: &v1alpha1.Volume{
Size: resource.MustParse("100Mi"),
},
},
},
TN: &v1alpha1.DNSetSpec{
PodSet: v1alpha1.PodSet{
// test multiple DN replicas
Replicas: 1,
},
CacheVolume: &v1alpha1.Volume{
Size: resource.MustParse("100Mi"),
},
},
LogService: v1alpha1.LogSetSpec{
PodSet: v1alpha1.PodSet{
Replicas: 3,
},
Volume: v1alpha1.Volume{
Size: resource.MustParse("100Mi"),
},
InitialConfig: v1alpha1.InitialConfig{},
},
Version: version,
ImageRepository: repo,
},
}
return mo
}
func NewNamespaceTpl() *corev1.Namespace {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "ns-" + rand.String(6),
},
}
return ns
}