Add Version, UpdateRuntimeConfig and Status.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
bc5dfdae24
commit
7c1a4c1fc1
@ -19,25 +19,25 @@ package server
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/truncindex"
|
|
||||||
"github.com/kubernetes-incubator/cri-o/pkg/ocicni"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
|
|
||||||
contentapi "github.com/containerd/containerd/api/services/content"
|
contentapi "github.com/containerd/containerd/api/services/content"
|
||||||
"github.com/containerd/containerd/api/services/execution"
|
"github.com/containerd/containerd/api/services/execution"
|
||||||
imagesapi "github.com/containerd/containerd/api/services/images"
|
imagesapi "github.com/containerd/containerd/api/services/images"
|
||||||
rootfsapi "github.com/containerd/containerd/api/services/rootfs"
|
rootfsapi "github.com/containerd/containerd/api/services/rootfs"
|
||||||
|
versionapi "github.com/containerd/containerd/api/services/version"
|
||||||
"github.com/containerd/containerd/content"
|
"github.com/containerd/containerd/content"
|
||||||
"github.com/containerd/containerd/images"
|
"github.com/containerd/containerd/images"
|
||||||
contentservice "github.com/containerd/containerd/services/content"
|
contentservice "github.com/containerd/containerd/services/content"
|
||||||
imagesservice "github.com/containerd/containerd/services/images"
|
imagesservice "github.com/containerd/containerd/services/images"
|
||||||
|
"github.com/docker/docker/pkg/truncindex"
|
||||||
|
"github.com/kubernetes-incubator/cri-o/pkg/ocicni"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
healthapi "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata"
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/metadata/store"
|
||||||
osinterface "github.com/kubernetes-incubator/cri-containerd/pkg/os"
|
osinterface "github.com/kubernetes-incubator/cri-containerd/pkg/os"
|
||||||
"github.com/kubernetes-incubator/cri-containerd/pkg/registrar"
|
"github.com/kubernetes-incubator/cri-containerd/pkg/registrar"
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO remove the underscores from the following imports as the services are
|
// TODO remove the underscores from the following imports as the services are
|
||||||
@ -86,13 +86,17 @@ type criContainerdService struct {
|
|||||||
containerNameIndex *registrar.Registrar
|
containerNameIndex *registrar.Registrar
|
||||||
// containerService is containerd container service client.
|
// containerService is containerd container service client.
|
||||||
containerService execution.ContainerServiceClient
|
containerService execution.ContainerServiceClient
|
||||||
// contentStoreService is the containerd content service client..
|
// contentStoreService is the containerd content service client.
|
||||||
contentStoreService content.Store
|
contentStoreService content.Store
|
||||||
// rootfsService is the containerd rootfs service client.
|
// rootfsService is the containerd rootfs service client.
|
||||||
rootfsService rootfsapi.RootFSClient
|
rootfsService rootfsapi.RootFSClient
|
||||||
// imageStoreService is the containerd service to store and track
|
// imageStoreService is the containerd service to store and track
|
||||||
// image metadata.
|
// image metadata.
|
||||||
imageStoreService images.Store
|
imageStoreService images.Store
|
||||||
|
// versionService is the containerd version service client.
|
||||||
|
versionService versionapi.VersionClient
|
||||||
|
// healthService is the healthcheck service of containerd grpc server.
|
||||||
|
healthService healthapi.HealthClient
|
||||||
// netPlugin is used to setup and teardown network when run/stop pod sandbox.
|
// netPlugin is used to setup and teardown network when run/stop pod sandbox.
|
||||||
netPlugin ocicni.CNIPlugin
|
netPlugin ocicni.CNIPlugin
|
||||||
}
|
}
|
||||||
@ -117,6 +121,8 @@ func NewCRIContainerdService(conn *grpc.ClientConn, rootDir, networkPluginBinDir
|
|||||||
imageStoreService: imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)),
|
imageStoreService: imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)),
|
||||||
contentStoreService: contentservice.NewStoreFromClient(contentapi.NewContentClient(conn)),
|
contentStoreService: contentservice.NewStoreFromClient(contentapi.NewContentClient(conn)),
|
||||||
rootfsService: rootfsapi.NewRootFSClient(conn),
|
rootfsService: rootfsapi.NewRootFSClient(conn),
|
||||||
|
versionService: versionapi.NewVersionClient(conn),
|
||||||
|
healthService: healthapi.NewHealthClient(conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
netPlugin, err := ocicni.InitCNI(networkPluginBinDir, networkPluginConfDir)
|
netPlugin, err := ocicni.InitCNI(networkPluginBinDir, networkPluginConfDir)
|
||||||
|
@ -17,14 +17,52 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
healthapi "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// runtimeNotReadyReason is the reason reported when runtime is not ready.
|
||||||
|
runtimeNotReadyReason = "ContainerdNotReady"
|
||||||
|
// networkNotReadyReason is the reason reported when network is not ready.
|
||||||
|
networkNotReadyReason = "NetworkPluginNotReady"
|
||||||
|
)
|
||||||
|
|
||||||
// Status returns the status of the runtime.
|
// Status returns the status of the runtime.
|
||||||
func (c *criContainerdService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) {
|
func (c *criContainerdService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) {
|
||||||
return nil, errors.New("not implemented")
|
runtimeCondition := &runtime.RuntimeCondition{
|
||||||
|
Type: runtime.RuntimeReady,
|
||||||
|
Status: true,
|
||||||
|
}
|
||||||
|
// Use containerd grpc server healthcheck service to check its readiness.
|
||||||
|
resp, err := c.healthService.Check(ctx, &healthapi.HealthCheckRequest{})
|
||||||
|
if err != nil || resp.Status != healthapi.HealthCheckResponse_SERVING {
|
||||||
|
runtimeCondition.Status = false
|
||||||
|
runtimeCondition.Reason = runtimeNotReadyReason
|
||||||
|
if err != nil {
|
||||||
|
runtimeCondition.Message = fmt.Sprintf("Containerd healthcheck returns error: %v", err)
|
||||||
|
} else {
|
||||||
|
runtimeCondition.Message = "Containerd grpc server is not serving"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
networkCondition := &runtime.RuntimeCondition{
|
||||||
|
Type: runtime.NetworkReady,
|
||||||
|
Status: true,
|
||||||
|
}
|
||||||
|
if err := c.netPlugin.Status(); err != nil {
|
||||||
|
networkCondition.Status = false
|
||||||
|
networkCondition.Reason = networkNotReadyReason
|
||||||
|
networkCondition.Message = fmt.Sprintf("Network plugin returns error: %v", err)
|
||||||
|
}
|
||||||
|
return &runtime.StatusResponse{
|
||||||
|
Status: &runtime.RuntimeStatus{Conditions: []*runtime.RuntimeCondition{
|
||||||
|
runtimeCondition,
|
||||||
|
networkCondition,
|
||||||
|
}},
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,13 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
|
// UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates.
|
||||||
|
// TODO(random-liu): Figure out how to handle pod cidr in cri-containerd.
|
||||||
func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) {
|
func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) {
|
||||||
return nil, errors.New("not implemented")
|
return &runtime.UpdateRuntimeConfigResponse{}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,35 @@ limitations under the License.
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
containerName = "containerd"
|
||||||
|
containerdAPIVersion = "0.0.0"
|
||||||
|
containerdVersion = "0.0.0"
|
||||||
|
// kubeAPIVersion is the api version of kubernetes.
|
||||||
|
kubeAPIVersion = "0.1.0"
|
||||||
|
)
|
||||||
|
|
||||||
// Version returns the runtime name, runtime version and runtime API version.
|
// Version returns the runtime name, runtime version and runtime API version.
|
||||||
func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) {
|
func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) {
|
||||||
return nil, errors.New("not implemented")
|
_, err := c.versionService.Version(ctx, &empty.Empty{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to get containerd version: %v", err)
|
||||||
|
}
|
||||||
|
return &runtime.VersionResponse{
|
||||||
|
Version: kubeAPIVersion,
|
||||||
|
RuntimeName: containerName,
|
||||||
|
// Containerd doesn't return semver because of a bug.
|
||||||
|
// TODO(random-liu): Replace this with version from containerd.
|
||||||
|
RuntimeVersion: containerdVersion,
|
||||||
|
// Containerd doesn't have an api version now.
|
||||||
|
RuntimeApiVersion: containerdAPIVersion,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user