Skip to content

Commit 9ae6d37

Browse files
authored
Resources StorageNodeSet and DatabaseNodeSet (#169)
* YDBOPS-8645 split Storage object to Storage and StorageNodeSet * YDBOPS-8646 split Database object to Database and DatabaseNodeSet
1 parent ddaf56b commit 9ae6d37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+15566
-1124
lines changed

.github/workflows/check-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: check-pr
2-
on:
2+
on:
33
pull_request_target:
44
branches:
55
- 'master'

.github/workflows/upload-artifacts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches:
88
- master
99
jobs:
10-
tag-job:
10+
tag-job:
1111
runs-on: ubuntu-latest
1212
outputs:
1313
tagcreated: ${{steps.tag-step.outputs.tagcreated}}
@@ -60,7 +60,7 @@ jobs:
6060
env:
6161
SA_KEYS_FOR_PRIVATE_DOCKER_HELM_AND_PUBLIC_DOCKER: ${{ secrets.SA_KEYS_FOR_PRIVATE_DOCKER_HELM_AND_PUBLIC_DOCKER }}
6262
- name: parse-version-from-chart
63-
run: |
63+
run: |
6464
VERSION=$(cat ./deploy/ydb-operator/Chart.yaml | sed -n 's/^version: //p')
6565
echo "VERSION=$VERSION" >> $GITHUB_ENV
6666
- name: login-to-registries

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4949
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5050
cp config/crd/bases/ydb.tech_storages.yaml deploy/ydb-operator/crds/storage.yaml
5151
cp config/crd/bases/ydb.tech_databases.yaml deploy/ydb-operator/crds/database.yaml
52+
cp config/crd/bases/ydb.tech_storagenodesets.yaml deploy/ydb-operator/crds/storagenodeset.yaml
53+
cp config/crd/bases/ydb.tech_databasenodesets.yaml deploy/ydb-operator/crds/databasenodeset.yaml
5254
cp config/crd/bases/ydb.tech_databasemonitorings.yaml deploy/ydb-operator/crds/databasemonitoring.yaml
5355
cp config/crd/bases/ydb.tech_storagemonitorings.yaml deploy/ydb-operator/crds/storagemonitoring.yaml
5456

@@ -61,13 +63,21 @@ fmt: ## Run go fmt against code.
6163
vet: ## Run go vet against code.
6264
go vet ./...
6365

64-
test: manifests generate fmt vet envtest docker-build ## Run tests.
65-
kind create cluster --config e2e/kind-cluster-config.yaml --name kind-ydb-operator
66+
kind-init:
67+
if kind get clusters | grep "kind-ydb-operator"; then exit 0; fi; \
68+
kind create cluster --config e2e/kind-cluster-config.yaml --name kind-ydb-operator; \
69+
docker pull k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.0; \
70+
kind load docker-image k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.0 --name kind-ydb-operator; \
71+
docker pull cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44; \
72+
kind load docker-image cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44 --name kind-ydb-operator
73+
74+
kind-load:
6675
docker tag cr.yandex/yc/ydb-operator:latest kind/ydb-operator:current
6776
kind load docker-image kind/ydb-operator:current --name kind-ydb-operator
68-
docker pull cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44
69-
kind load docker-image cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44 --name kind-ydb-operator
70-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -timeout 1800s -p 1 ./... -coverprofile cover.out
77+
78+
.PHONY: test
79+
test: manifests generate fmt vet docker-build kind-init kind-load envtest ## Run tests.
80+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -timeout 1800s -p 1 ./... -ginkgo.v -coverprofile cover.out
7181

7282
.PHONY: clean
7383
clean:

api/v1alpha1/common_types.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package v1alpha1
22

3+
import corev1 "k8s.io/api/core/v1"
4+
35
// NamespacedRef TODO: replace StorageRef
46
type NamespacedRef struct {
57
// +kubebuilder:validation:Pattern:=[a-z0-9]([-a-z0-9]*[a-z0-9])?
@@ -12,3 +14,23 @@ type NamespacedRef struct {
1214
// +optional
1315
Namespace string `json:"namespace"`
1416
}
17+
18+
// PodImage represents the image information for a container that is used
19+
// to build the StatefulSet.
20+
type PodImage struct {
21+
// Container image with supported YDB version.
22+
// This defaults to the version pinned to the operator and requires a full container and tag/sha name.
23+
// For example: cr.yandex/crptqonuodf51kdj7a7d/ydb:22.2.22
24+
// +optional
25+
Name string `json:"name,omitempty"`
26+
27+
// (Optional) PullPolicy for the image, which defaults to IfNotPresent.
28+
// Default: IfNotPresent
29+
// +optional
30+
PullPolicyName *corev1.PullPolicy `json:"pullPolicy,omitempty"`
31+
32+
// (Optional) Secret name containing the dockerconfig to use for a registry that requires authentication. The secret
33+
// must be configured first by the user.
34+
// +optional
35+
PullSecret *string `json:"pullSecret,omitempty"`
36+
}

internal/configuration/configuration.go renamed to api/v1alpha1/configuration.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package configuration
1+
package v1alpha1
22

33
import (
44
"crypto/sha256"
@@ -8,7 +8,6 @@ import (
88

99
"gopkg.in/yaml.v3"
1010

11-
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1211
"github.com/ydb-platform/ydb-kubernetes-operator/internal/configuration/schema"
1312
)
1413

@@ -25,20 +24,20 @@ func hash(text string) string {
2524
return fmt.Sprintf("%x", h.Sum(nil))
2625
}
2726

28-
func generateSomeDefaults(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.Configuration {
27+
func generateSomeDefaults(cr *Storage, crDB *Database) schema.Configuration {
2928
var hosts []schema.Host
3029

3130
for i := 0; i < int(cr.Spec.Nodes); i++ {
3231
datacenter := "az-1"
33-
if cr.Spec.Erasure == v1alpha1.ErasureMirror3DC {
32+
if cr.Spec.Erasure == ErasureMirror3DC {
3433
datacenter = fmt.Sprintf("az-%d", i%3)
3534
}
3635

3736
hosts = append(hosts, schema.Host{
3837
Host: fmt.Sprintf("%v-%d", cr.GetName(), i),
3938
HostConfigID: 1, // TODO
4039
NodeID: i + 1,
41-
Port: v1alpha1.InterconnectPort,
40+
Port: InterconnectPort,
4241
WalleLocation: schema.WalleLocation{
4342
Body: 12340 + i,
4443
DataCenter: datacenter,
@@ -47,6 +46,17 @@ func generateSomeDefaults(cr *v1alpha1.Storage, crDB *v1alpha1.Database) schema.
4746
})
4847
}
4948

49+
if cr.Spec.NodeSets != nil {
50+
hostIndex := 0
51+
for _, nodeSetSpec := range cr.Spec.NodeSets {
52+
for podIndex := 0; podIndex < int(nodeSetSpec.Nodes); podIndex++ {
53+
podName := cr.GetName() + "-" + nodeSetSpec.Name + "-" + strconv.Itoa(podIndex)
54+
hosts[hostIndex].Host = podName
55+
hostIndex++
56+
}
57+
}
58+
}
59+
5060
var keyConfig *schema.KeyConfig
5161
if crDB != nil && crDB.Spec.Encryption != nil && crDB.Spec.Encryption.Enabled {
5262
keyConfig = &schema.KeyConfig{
@@ -79,7 +89,7 @@ func tryFillMissingSections(
7989
}
8090
}
8191

82-
func Build(cr *v1alpha1.Storage, crDB *v1alpha1.Database) (map[string]string, error) {
92+
func buildConfiguration(cr *Storage, crDB *Database) (string, error) {
8393
config := make(map[string]interface{})
8494

8595
// If any kind of configuration exists on Database object, then
@@ -95,20 +105,16 @@ func Build(cr *v1alpha1.Storage, crDB *v1alpha1.Database) (map[string]string, er
95105

96106
err := yaml.Unmarshal([]byte(rawYamlConfiguration), &config)
97107
if err != nil {
98-
return nil, err
108+
return "", err
99109
}
100110

101111
generatedConfig := generateSomeDefaults(cr, crDB)
102112
tryFillMissingSections(config, generatedConfig)
103113

104114
data, err := yaml.Marshal(config)
105115
if err != nil {
106-
return nil, err
116+
return "", err
107117
}
108118

109-
result := string(data)
110-
111-
return map[string]string{
112-
v1alpha1.ConfigFileName: result,
113-
}, nil
119+
return string(data), nil
114120
}

api/v1alpha1/const.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ const (
66

77
ImagePathFormat = "%s:%s"
88

9-
GRPCPort = 2135
10-
GRPCServicePortName = "grpc"
11-
GRPCProto = "grpc://"
12-
GRPCSProto = "grpcs://"
13-
14-
InterconnectPort = 19001
15-
InterconnectServicePortName = "interconnect"
9+
GRPCPort = 2135
10+
GRPCServicePortName = "grpc"
11+
GRPCProto = "grpc://"
12+
GRPCSProto = "grpcs://"
13+
GRPCServiceFQDNFormat = "%s-grpc.%s.svc.cluster.local"
14+
15+
InterconnectPort = 19001
16+
InterconnectServicePortName = "interconnect"
17+
InterconnectServiceFQDNFormat = "%s-interconnect.%s.svc.cluster.local"
1618

1719
StatusPort = 8765
1820
StatusServicePortName = "status"

api/v1alpha1/database_defaults.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)