Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
juanluisvaladas committed Jan 23, 2023
1 parent 412ca49 commit 6e445f2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cmd/containerd/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package command

import (
gocontext "context"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -116,6 +117,15 @@ var configCommand = cli.Command{
return err
}

tree := config.Plugins["io.containerd.grpc.v1.cri"]
containerd := tree.Get("containerd").(toml.Tree)
runtimes := containerd.Get("runtimes").(toml.Tree)
foo := runtimes.Get("foo").(toml.Tree)
fmt.Printf("%p\n", tree)
fmt.Printf("%#v\n", tree)
fmt.Printf("%#v\n", containerd)
fmt.Printf("%#v\n", runtimes)
fmt.Printf("%#v\n", foo)
return outputConfig(config)
},
},
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ require (
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
)

require golang.org/x/exp v0.0.0-20230116083435-1de6713980de

require (
cloud.google.com/go/compute/metadata v0.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230116083435-1de6713980de h1:DBWn//IJw30uYCgERoxCg84hWtA97F4wMiKOIh00Uf0=
golang.org/x/exp v0.0.0-20230116083435-1de6713980de/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
35 changes: 32 additions & 3 deletions services/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package config
import (
"fmt"
"path/filepath"
"reflect"
"strings"

"github.com/imdario/mergo"
Expand Down Expand Up @@ -293,11 +294,17 @@ func mergeConfig(to, from *Config) error {
return err
}

// Replace entire sections instead of merging map's values.
for k, v := range from.Plugins {
to.Plugins[k] = v
for k := range from.Plugins {
// If plugin is not present in the target config, just copy the whole section.
if _, ok := to.Plugins[k]; !ok {
to.Plugins[k] = from.Plugins[k]
continue
}

to.Plugins[k] = mergeTrees(to.Plugins[k], from.Plugins[k])
}

// Replace entire sections instead of merging map's values.
for k, v := range from.StreamProcessors {
to.StreamProcessors[k] = v
}
Expand All @@ -313,6 +320,28 @@ func mergeConfig(to, from *Config) error {
return nil
}

func isTree(v interface{}) bool {
return reflect.TypeOf(v).String() == "*toml.Tree"
}

func mergeTrees(to, from toml.Tree) toml.Tree {
for _, k := range from.Keys() {
if !to.Has(k) {
to.Set(k, from.Get(k))
continue
}
if isTree(to.Get(k)) && isTree(from.Get(k)) {
t := to.Get(k).(*toml.Tree)
f := from.Get(k).(*toml.Tree)
to.Set(k, mergeTrees(*t, *f))
} else {
// If not a tree, it's a tomlValue and we just replace it.
// to.Set(k, from.Get(k))
}
}
return to
}

// V1DisabledFilter matches based on ID
func V1DisabledFilter(list []string) plugin.DisableFilter {
set := make(map[string]struct{}, len(list))
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ golang.org/x/crypto/openpgp/errors
golang.org/x/crypto/openpgp/packet
golang.org/x/crypto/openpgp/s2k
golang.org/x/crypto/pbkdf2
# golang.org/x/exp v0.0.0-20230116083435-1de6713980de
## explicit; go 1.18
# golang.org/x/mod v0.6.0
## explicit; go 1.17
golang.org/x/mod/semver
Expand Down

0 comments on commit 6e445f2

Please sign in to comment.