Skip to content

Commit

Permalink
fix: pass a pointer to specs.Mount into protoenc.Marshal
Browse files Browse the repository at this point in the history
Encoder function `protoenc.Marshal` expects a pointer.

Fixes siderolabs#6233

Signed-off-by: Dmitriy Matrenichev <[email protected]>
  • Loading branch information
DmitriyMV committed Sep 8, 2022
1 parent e626540 commit 3146245
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/machinery/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func registerDefaultTypes() {

protoenc.RegisterEncoderDecoder(
func(v specs.Mount) ([]byte, error) {
return protoenc.Marshal(Mount(v))
mount := Mount(v)

return protoenc.Marshal(&mount)
},
func(slc []byte) (specs.Mount, error) {
var result Mount
Expand Down
39 changes: 39 additions & 0 deletions pkg/machinery/resources/k8s/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import (
"testing"

"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/protobuf"
"github.com/cosi-project/runtime/pkg/state"
"github.com/cosi-project/runtime/pkg/state/impl/inmem"
"github.com/cosi-project/runtime/pkg/state/impl/namespaced"
"github.com/cosi-project/runtime/pkg/state/registry"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/talos-systems/talos/pkg/machinery/resources/k8s"
)
Expand Down Expand Up @@ -48,3 +51,39 @@ func TestRegisterResource(t *testing.T) {
assert.NoError(t, resourceRegistry.Register(ctx, resource))
}
}

func TestKubeletConfig(t *testing.T) {
cfg := k8s.NewKubeletConfig(k8s.NamespaceName, k8s.KubeletID)
cfg.TypedSpec().Image = "kubelet:v1.0.0"
cfg.TypedSpec().ClusterDNS = []string{"10.96.0.10"}
cfg.TypedSpec().ClusterDomain = "cluster.local"
cfg.TypedSpec().ExtraArgs = map[string]string{"foo": "bar"}
cfg.TypedSpec().ExtraMounts = []specs.Mount{
{
Destination: "/tmp",
Source: "/var",
Type: "tmpfs",
},
}
cfg.TypedSpec().CloudProviderExternal = true

res, err := protobuf.FromResource(cfg)
require.NoError(t, err)
require.NotNil(t, res)
}

func TestKubeletSpec(t *testing.T) {
cfg := k8s.NewKubeletSpec(k8s.NamespaceName, k8s.KubeletID)
cfg.TypedSpec().Image = "kubelet:v1.0.0"
cfg.TypedSpec().ExtraMounts = []specs.Mount{
{
Destination: "/tmp",
Source: "/var",
Type: "tmpfs",
},
}

res, err := protobuf.FromResource(cfg)
require.NoError(t, err)
require.NotNil(t, res)
}

0 comments on commit 3146245

Please sign in to comment.