Skip to content

Commit b9442a9

Browse files
committed
Merge branch 'master' into propagate-annotations
2 parents 58ddbb4 + 0b791fa commit b9442a9

34 files changed

+1254
-151
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ jobs:
163163
kind load docker-image cr.yandex/crptqonuodf51kdj7a7d/ydb:23.3.17
164164
- name: run-tests
165165
run: |
166-
go test -v -timeout 1800s -p 1 ./... -args -ginkgo.v
166+
go test -v -timeout 3600s -p 1 ./... -args -ginkgo.v
167167
- name: teardown-k8s-cluster
168168
run: |
169169
kind delete cluster

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ kind-load:
7979

8080
.PHONY: unit-test
8181
unit-test: manifests generate fmt vet envtest ## Run unit tests
82-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use --arch=amd64 $(ENVTEST_K8S_VERSION) -p path)" go test -v -timeout 1800s -p 1 ./internal/controllers/... -ginkgo.v -coverprofile cover.out
82+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use --arch=amd64 $(ENVTEST_K8S_VERSION) -p path)" go test -v -timeout 1800s -p 1 ./internal/... -ginkgo.v -coverprofile cover.out
8383

8484
.PHONY: e2e-test
8585
e2e-test: manifests generate fmt vet docker-build kind-init kind-load ## Run e2e tests

api/v1alpha1/configuration.go

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

33
import (
4+
"bytes"
45
"crypto/sha256"
56
"fmt"
67
"path"
@@ -24,7 +25,7 @@ func hash(text string) string {
2425
return fmt.Sprintf("%x", h.Sum(nil))
2526
}
2627

27-
func generateSomeDefaults(cr *Storage, crDB *Database) schema.Configuration {
28+
func generateHosts(cr *Storage) []schema.Host {
2829
var hosts []schema.Host
2930

3031
for i := 0; i < int(cr.Spec.Nodes); i++ {
@@ -57,6 +58,10 @@ func generateSomeDefaults(cr *Storage, crDB *Database) schema.Configuration {
5758
}
5859
}
5960

61+
return hosts
62+
}
63+
64+
func generateKeyConfig(cr *Storage, crDB *Database) *schema.KeyConfig {
6065
var keyConfig *schema.KeyConfig
6166
if crDB != nil && crDB.Spec.Encryption != nil && crDB.Spec.Encryption.Enabled {
6267
keyConfig = &schema.KeyConfig{
@@ -71,25 +76,10 @@ func generateSomeDefaults(cr *Storage, crDB *Database) schema.Configuration {
7176
}
7277
}
7378

74-
return schema.Configuration{
75-
Hosts: hosts,
76-
KeyConfig: keyConfig,
77-
}
79+
return keyConfig
7880
}
7981

80-
func tryFillMissingSections(
81-
resultConfig map[string]interface{},
82-
generatedConfig schema.Configuration,
83-
) {
84-
if resultConfig["hosts"] == nil {
85-
resultConfig["hosts"] = generatedConfig.Hosts
86-
}
87-
if generatedConfig.KeyConfig != nil {
88-
resultConfig["key_config"] = generatedConfig.KeyConfig
89-
}
90-
}
91-
92-
func BuildConfiguration(cr *Storage, crDB *Database) (string, error) {
82+
func BuildConfiguration(cr *Storage, crDB *Database) ([]byte, error) {
9383
config := make(map[string]interface{})
9484

9585
// If any kind of configuration exists on Database object, then
@@ -103,18 +93,47 @@ func BuildConfiguration(cr *Storage, crDB *Database) (string, error) {
10393
rawYamlConfiguration = cr.Spec.Configuration
10494
}
10595

106-
err := yaml.Unmarshal([]byte(rawYamlConfiguration), &config)
96+
dynconfig, err := ParseDynconfig(rawYamlConfiguration)
97+
if err == nil {
98+
if dynconfig.Config["hosts"] == nil {
99+
hosts := generateHosts(cr)
100+
dynconfig.Config["hosts"] = hosts
101+
}
102+
103+
return yaml.Marshal(dynconfig)
104+
}
105+
106+
err = yaml.Unmarshal([]byte(rawYamlConfiguration), &config)
107107
if err != nil {
108-
return "", err
108+
return nil, err
109109
}
110110

111-
generatedConfig := generateSomeDefaults(cr, crDB)
112-
tryFillMissingSections(config, generatedConfig)
111+
if config["hosts"] == nil {
112+
hosts := generateHosts(cr)
113+
config["hosts"] = hosts
114+
}
113115

114-
data, err := yaml.Marshal(config)
115-
if err != nil {
116-
return "", err
116+
// Will be removed by YDBOPS-9692
117+
keyConfig := generateKeyConfig(cr, crDB)
118+
if keyConfig != nil {
119+
config["key_config"] = keyConfig
117120
}
118121

119-
return string(data), nil
122+
return yaml.Marshal(config)
123+
}
124+
125+
func ParseConfig(rawYamlConfiguration string) (schema.Configuration, error) {
126+
config := schema.Configuration{}
127+
dec := yaml.NewDecoder(bytes.NewReader([]byte(rawYamlConfiguration)))
128+
dec.KnownFields(false)
129+
err := dec.Decode(&config)
130+
return config, err
131+
}
132+
133+
func ParseDynconfig(rawYamlConfiguration string) (schema.Dynconfig, error) {
134+
dynconfig := schema.Dynconfig{}
135+
dec := yaml.NewDecoder(bytes.NewReader([]byte(rawYamlConfiguration)))
136+
dec.KnownFields(true)
137+
err := dec.Decode(&dynconfig)
138+
return dynconfig, err
120139
}

api/v1alpha1/connection_types.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
)
66

77
type ConnectionOptions struct {
8-
AccessToken *AccessTokenAuth `json:"accessToken,omitempty"`
9-
StaticCredentials *StaticCredentialsAuth `json:"staticCredentials,omitempty"`
8+
AccessToken *AccessTokenAuth `json:"accessToken,omitempty"`
9+
StaticCredentials *StaticCredentialsAuth `json:"staticCredentials,omitempty"`
10+
Oauth2TokenExhange *Oauth2TokenExchange `json:"oauth2TokenExchange,omitempty"`
1011
}
1112

1213
type AccessTokenAuth struct {
@@ -18,6 +19,24 @@ type StaticCredentialsAuth struct {
1819
Password *CredentialSource `json:"password,omitempty"`
1920
}
2021

22+
type Oauth2TokenExchange struct {
23+
Endpoint string `json:"endpoint"`
24+
PrivateKey *CredentialSource `json:"privateKey"`
25+
JWTHeader *JWTHeader `json:",inline"`
26+
JWTClaims *JWTClaims `json:",inline"`
27+
}
28+
29+
type JWTHeader struct {
30+
KeyID string `json:"keyID,omitempty"`
31+
SignAlg string `json:"signAlg,omitempty"`
32+
}
33+
type JWTClaims struct {
34+
Issuer string `json:"issuer,omitempty"`
35+
Subject string `json:"subject,omitempty"`
36+
Audience string `json:"audience,omitempty"`
37+
ID string `json:"id,omitempty"`
38+
}
39+
2140
type CredentialSource struct {
2241
SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef"`
2342
}

api/v1alpha1/database_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,6 @@ func init() {
268268
func (r *Database) AnyCertificatesAdded() bool {
269269
return len(r.Spec.CABundle) > 0 ||
270270
r.Spec.Service.GRPC.TLSConfiguration.Enabled ||
271-
r.Spec.Service.Interconnect.TLSConfiguration.Enabled
271+
r.Spec.Service.Interconnect.TLSConfiguration.Enabled ||
272+
r.Spec.Service.Status.TLSConfiguration.Enabled
272273
}

api/v1alpha1/database_webhook.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
5959
database := obj.(*Database)
6060
databaselog.Info("default", "name", database.Name)
6161

62+
if !database.Spec.OperatorSync {
63+
return nil
64+
}
65+
6266
if database.Spec.StorageClusterRef.Namespace == "" {
6367
database.Spec.StorageClusterRef.Namespace = database.Namespace
6468
}
@@ -107,6 +111,10 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
107111
database.Spec.Service.Datastreams.TLSConfiguration = &TLSConfiguration{Enabled: false}
108112
}
109113

114+
if database.Spec.Service.Status.TLSConfiguration == nil {
115+
database.Spec.Service.Status.TLSConfiguration = &TLSConfiguration{Enabled: false}
116+
}
117+
110118
if database.Spec.Domain == "" {
111119
database.Spec.Domain = DefaultDatabaseDomain
112120
}
@@ -147,7 +155,7 @@ func (r *DatabaseDefaulter) Default(ctx context.Context, obj runtime.Object) err
147155
if err != nil {
148156
return err
149157
}
150-
database.Spec.Configuration = configuration
158+
database.Spec.Configuration = string(configuration)
151159
}
152160

153161
if database.Spec.AdditionalAnnotations == nil {

api/v1alpha1/service_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type InterconnectService struct {
3232

3333
type StatusService struct {
3434
Service `json:""`
35+
36+
TLSConfiguration *TLSConfiguration `json:"tls,omitempty"`
3537
}
3638

3739
type DatastreamsService struct {

api/v1alpha1/storage_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,6 @@ func init() {
242242
func (r *Storage) AnyCertificatesAdded() bool {
243243
return len(r.Spec.CABundle) > 0 ||
244244
r.Spec.Service.GRPC.TLSConfiguration.Enabled ||
245-
r.Spec.Service.Interconnect.TLSConfiguration.Enabled
245+
r.Spec.Service.Interconnect.TLSConfiguration.Enabled ||
246+
r.Spec.Service.Status.TLSConfiguration.Enabled
246247
}

0 commit comments

Comments
 (0)