Skip to content

Commit

Permalink
add sidecars support to primary masters containers (#259)
Browse files Browse the repository at this point in the history
* add sidecars support to primary masters containers

* add ytop-chart/templates/ytsaurus-crd.yaml

---------

Co-authored-by: Konstantin Malov <[email protected]>
  • Loading branch information
kmalov and Konstantin Malov authored May 18, 2024
1 parent e4ddb54 commit 61f83a2
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/v1/ytsaurus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ type MastersSpec struct {

MaxSnapshotCountToKeep *int `json:"maxSnapshotCountToKeep,omitempty"`
MaxChangelogCountToKeep *int `json:"maxChangelogCountToKeep,omitempty"`

Sidecars []string `json:"sidecars,omitempty"`
}

type HTTPTransportSpec struct {
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/cluster.ytsaurus.tech_ytsaurus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15262,6 +15262,10 @@ spec:
type: object
runtimeClassName:
type: string
sidecars:
items:
type: string
type: array
structuredLoggers:
items:
properties:
Expand Down Expand Up @@ -26953,6 +26957,10 @@ spec:
type: object
runtimeClassName:
type: string
sidecars:
items:
type: string
type: array
structuredLoggers:
items:
properties:
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ _Appears in:_
| `hostAddressLabel` _string_ | | | |
| `maxSnapshotCountToKeep` _integer_ | | | |
| `maxChangelogCountToKeep` _integer_ | | | |
| `sidecars` _string array_ | | | |


#### OauthServiceSpec
Expand Down
9 changes: 2 additions & 7 deletions pkg/components/exec_node_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/yaml"
ptr "k8s.io/utils/pointer"

ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1"
Expand Down Expand Up @@ -94,12 +93,8 @@ func (n *baseExecNode) doBuildBase() error {
})
}

for _, sidecarSpec := range n.spec.Sidecars {
sidecar := corev1.Container{}
if err := yaml.Unmarshal([]byte(sidecarSpec), &sidecar); err != nil {
return err
}
podSpec.Containers = append(podSpec.Containers, sidecar)
if err := AddSidecarsToPodSpec(n.spec.Sidecars, podSpec); err != nil {
return err
}

if n.sidecarConfig != nil {
Expand Down
16 changes: 15 additions & 1 deletion pkg/components/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package components
import (
"context"
"fmt"
"strings"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"strings"

"k8s.io/apimachinery/pkg/util/yaml"

"go.ytsaurus.tech/library/go/ptr"
"go.ytsaurus.tech/yt/go/ypath"
Expand Down Expand Up @@ -202,3 +205,14 @@ func AddAffinity(statefulSet *appsv1.StatefulSet,
affinity.NodeAffinity = nodeAffinity
statefulSet.Spec.Template.Spec.Affinity = affinity
}

func AddSidecarsToPodSpec(sidecar []string, podSpec *corev1.PodSpec) error {
for _, sidecarSpec := range sidecar {
sidecar := corev1.Container{}
if err := yaml.Unmarshal([]byte(sidecarSpec), &sidecar); err != nil {
return err
}
podSpec.Containers = append(podSpec.Containers, sidecar)
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/components/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ func (m *Master) Sync(ctx context.Context) error {

func (m *Master) doServerSync(ctx context.Context) error {
statefulSet := m.server.buildStatefulSet()
podSpec := &statefulSet.Spec.Template.Spec
primaryMastersSpec := m.ytsaurus.GetResource().Spec.PrimaryMasters

if err := AddSidecarsToPodSpec(primaryMastersSpec.Sidecars, podSpec); err != nil {
return err
}

if len(primaryMastersSpec.HostAddresses) != 0 {
AddAffinity(statefulSet, m.getHostAddressLabel(), primaryMastersSpec.HostAddresses)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/ytconfig/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,10 @@ func getYtsaurus() *ytv1.Ytsaurus {
},
},
},

Sidecars: []string{
"{name: sleep, image: fakeimage:stable, command: [/bin/sleep], args: [inf]}",
},
},
},
}
Expand Down
8 changes: 8 additions & 0 deletions ytop-chart/templates/ytsaurus-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15175,6 +15175,10 @@ spec:
type: object
runtimeClassName:
type: string
sidecars:
items:
type: string
type: array
structuredLoggers:
items:
properties:
Expand Down Expand Up @@ -26775,6 +26779,10 @@ spec:
type: object
runtimeClassName:
type: string
sidecars:
items:
type: string
type: array
structuredLoggers:
items:
properties:
Expand Down

0 comments on commit 61f83a2

Please sign in to comment.