Skip to content

Commit

Permalink
Add RuntimeHandler into PodSandbox and PodSandboxStatus
Browse files Browse the repository at this point in the history
The upstream CRI change: kubernetes/kubernetes#73833

Signed-off-by: Haiyan Meng <haiyanmeng@google.com>
  • Loading branch information
haiyanmeng committed Feb 27, 2019
1 parent ec3aa44 commit f69f35b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 23 deletions.
50 changes: 50 additions & 0 deletions integration/runtime_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
)

func TestRuntimeHanlder(t *testing.T) {
ctx := context.Background()
t.Logf("Create a sandbox")
sbConfig := PodSandboxConfig("sandbox", "test-runtime-handler")
runtimeHandler := "gvisor"
sb, err := runtimeService.RunPodSandbox(sbConfig, runtimeHandler)
require.NoError(t, err)
defer func() {
// Make sure the sandbox is cleaned up in any case.
runtimeService.StopPodSandbox(sb)
runtimeService.RemovePodSandbox(sb)
}()

t.Logf("Verify runtimeService.PodSandboxStatus sets RuntimeHandler")
sbStatus, err := runtimeService.PodSandboxStatus(sb)
require.NoError(t, err)
assert.Equal(t, runtimehandler, sbStatus.RuntimeHandler)

t.Logf("Verify runtimeService.ListPodSandbox sets RuntimeHandler")
sandboxes, err := runtimeService.ListPodSandbox(&runtime.PodSandboxFilter{})
require.NoError(t, err)
assert.Equal(t, runtimehandler, sandboxes[0].RuntimeHandler)
}
13 changes: 7 additions & 6 deletions pkg/server/sandbox_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ func toCRISandbox(meta sandboxstore.Metadata, status sandboxstore.Status) *runti
state = runtime.PodSandboxState_SANDBOX_READY
}
return &runtime.PodSandbox{
Id: meta.ID,
Metadata: meta.Config.GetMetadata(),
State: state,
CreatedAt: status.CreatedAt.UnixNano(),
Labels: meta.Config.GetLabels(),
Annotations: meta.Config.GetAnnotations(),
Id: meta.ID,
Metadata: meta.Config.GetMetadata(),
State: state,
CreatedAt: status.CreatedAt.UnixNano(),
Labels: meta.Config.GetLabels(),
Annotations: meta.Config.GetAnnotations(),
RuntimeHandler: meta.RuntimeHandler,
}
}

Expand Down
23 changes: 14 additions & 9 deletions pkg/server/sandbox_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ func TestToCRISandbox(t *testing.T) {
}
createdAt := time.Now()
meta := sandboxstore.Metadata{
ID: "test-id",
Name: "test-name",
Config: config,
NetNSPath: "test-netns",
ID: "test-id",
Name: "test-name",
Config: config,
NetNSPath: "test-netns",
RuntimeHandler: "gvisor",
}
expect := &runtime.PodSandbox{
Id: "test-id",
Metadata: config.GetMetadata(),
CreatedAt: createdAt.UnixNano(),
Labels: config.GetLabels(),
Annotations: config.GetAnnotations(),
Id: "test-id",
Metadata: config.GetMetadata(),
CreatedAt: createdAt.UnixNano(),
Labels: config.GetLabels(),
Annotations: config.GetAnnotations(),
RuntimeHandler: "gvisor",
}
for desc, test := range map[string]struct {
state sandboxstore.State
Expand Down Expand Up @@ -93,6 +95,7 @@ func TestFilterSandboxes(t *testing.T) {
Attempt: 1,
},
},
RuntimeHandler: "gvisor",
},
sandboxstore.Status{
CreatedAt: time.Now(),
Expand All @@ -112,6 +115,7 @@ func TestFilterSandboxes(t *testing.T) {
},
Labels: map[string]string{"a": "b"},
},
RuntimeHandler: "gvisor",
},
sandboxstore.Status{
CreatedAt: time.Now(),
Expand All @@ -131,6 +135,7 @@ func TestFilterSandboxes(t *testing.T) {
},
Labels: map[string]string{"c": "d"},
},
RuntimeHandler: "gvisor",
},
sandboxstore.Status{
CreatedAt: time.Now(),
Expand Down
9 changes: 6 additions & 3 deletions pkg/server/sandbox_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,24 @@ func toCRISandboxStatus(meta sandboxstore.Metadata, status sandboxstore.Status,
},
},
},
Labels: meta.Config.GetLabels(),
Annotations: meta.Config.GetAnnotations(),
Labels: meta.Config.GetLabels(),
Annotations: meta.Config.GetAnnotations(),
RuntimeHanlder: meta.RuntimeHandler,
}
}

// SandboxInfo is extra information for sandbox.
// TODO (mikebrow): discuss predefining constants structures for some or all of these field names in CRI
type SandboxInfo struct {
// Note: a new field `RuntimeHandler` has been added into the CRI PodSandboxStatus struct, and
// should be used. This `RuntimeHandler` field here will be deprecated after a grace period.
Pid uint32 `json:"pid"`
Status string `json:"processStatus"`
NetNSClosed bool `json:"netNamespaceClosed"`
Image string `json:"image"`
SnapshotKey string `json:"snapshotKey"`
Snapshotter string `json:"snapshotter"`
RuntimeHandler string `json:"runtimeHandler"`
RuntimeHandler string `json:"runtimeHandler"` // see the Note above
RuntimeType string `json:"runtimeType"`
RuntimeOptions interface{} `json:"runtimeOptions"`
Config *runtime.PodSandboxConfig `json:"config"`
Expand Down
12 changes: 7 additions & 5 deletions pkg/server/sandbox_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func TestPodSandboxStatus(t *testing.T) {
Annotations: map[string]string{"c": "d"},
}
metadata := sandboxstore.Metadata{
ID: id,
Name: "test-name",
Config: config,
ID: id,
Name: "test-name",
Config: config,
RuntimeHandler: "gvisor",
}

expected := &runtime.PodSandboxStatus{
Expand All @@ -71,8 +72,9 @@ func TestPodSandboxStatus(t *testing.T) {
},
},
},
Labels: config.GetLabels(),
Annotations: config.GetAnnotations(),
Labels: config.GetLabels(),
Annotations: config.GetAnnotations(),
RuntimeHandler: "gvisor",
}
for desc, test := range map[string]struct {
state sandboxstore.State
Expand Down

0 comments on commit f69f35b

Please sign in to comment.