Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crictl update-runtime-config command #1473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func main() {
checkpointContainerCommand,
runtimeConfigCommand,
eventsCommand,
updateRuntimeConfigCommand,
}

runtimeEndpointUsage := fmt.Sprintf("Endpoint of CRI container runtime "+
Expand Down
67 changes: 67 additions & 0 deletions cmd/crictl/update_runtime_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2024 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 main

import (
"context"
"fmt"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
pb "k8s.io/cri-api/pkg/apis/runtime/v1"
)

const (
podCIDRFlag = "pod-cidr"
)

var updateRuntimeConfigCommand = &cli.Command{
Name: "update-runtime-config",
Usage: "Update the runtime configuration",
UseShortOptionHandling: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: podCIDRFlag,
Aliases: []string{"p"},
Usage: "The new Classless Inter-Domain Routing (CIDR) value to be used for pod IP addresses. If the CIDR is empty, runtimes should omit it.",
},
},
Action: func(c *cli.Context) error {
if c.NArg() != 0 || c.NumFlags() == 0 {
return cli.ShowSubcommandHelp(c)
}

runtimeConfig := &pb.RuntimeConfig{}
if c.IsSet(podCIDRFlag) {
runtimeConfig.NetworkConfig = &pb.NetworkConfig{PodCidr: c.String(podCIDRFlag)}
}

runtimeClient, err := getRuntimeService(c, 0)
if err != nil {
return err
}

if _, err := InterruptableRPC(nil, func(ctx context.Context) (any, error) {
return nil, runtimeClient.UpdateRuntimeConfig(ctx, runtimeConfig)
}); err != nil {
return fmt.Errorf("update runtime config: %w", err)
}

logrus.Info("Runtime config successfully updated")
return nil
},
}
64 changes: 33 additions & 31 deletions docs/crictl.1
Original file line number Diff line number Diff line change
Expand Up @@ -73,67 +73,69 @@ COMMANDS:

.RS
.IP \(bu 2
\fB\fCattach\fR: Attach to a running container
\fB\fCattach\fR: Attach to a running container
.IP \(bu 2
\fB\fCcreate\fR: Create a new container
\fB\fCcreate\fR: Create a new container
.IP \(bu 2
\fB\fCexec\fR: Run a command in a running container
\fB\fCexec\fR: Run a command in a running container
.IP \(bu 2
\fB\fCversion\fR: Display runtime version information
\fB\fCversion\fR: Display runtime version information
.IP \(bu 2
\fB\fCimages, image, img\fR: List images
\fB\fCimages, image, img\fR: List images
.IP \(bu 2
\fB\fCinspect\fR: Display the status of one or more containers
\fB\fCinspect\fR: Display the status of one or more containers
.IP \(bu 2
\fB\fCinspecti\fR: Return the status of one or more images
\fB\fCinspecti\fR: Return the status of one or more images
.IP \(bu 2
\fB\fCimagefsinfo\fR: Return image filesystem info
\fB\fCimagefsinfo\fR: Return image filesystem info
.IP \(bu 2
\fB\fCinspectp\fR: Display the status of one or more pods
\fB\fCinspectp\fR: Display the status of one or more pods
.IP \(bu 2
\fB\fClogs\fR: Fetch the logs of a container
\fB\fClogs\fR: Fetch the logs of a container
.IP \(bu 2
\fB\fCport\-forward\fR: Forward local port to a pod
\fB\fCport\-forward\fR: Forward local port to a pod
.IP \(bu 2
\fB\fCps\fR: List containers
\fB\fCps\fR: List containers
.IP \(bu 2
\fB\fCpull\fR: Pull an image from a registry
\fB\fCpull\fR: Pull an image from a registry
.IP \(bu 2
\fB\fCrun\fR: Run a new container inside a sandbox
\fB\fCrun\fR: Run a new container inside a sandbox
.IP \(bu 2
\fB\fCrunp\fR: Run a new pod
\fB\fCrunp\fR: Run a new pod
.IP \(bu 2
\fB\fCrm\fR: Remove one or more containers
\fB\fCrm\fR: Remove one or more containers
.IP \(bu 2
\fB\fCrmi\fR: Remove one or more images
\fB\fCrmi\fR: Remove one or more images
.IP \(bu 2
\fB\fCrmp\fR: Remove one or more pods
\fB\fCrmp\fR: Remove one or more pods
.IP \(bu 2
\fB\fCpods\fR: List pods
\fB\fCpods\fR: List pods
.IP \(bu 2
\fB\fCstart\fR: Start one or more created containers
\fB\fCstart\fR: Start one or more created containers
.IP \(bu 2
\fB\fCinfo\fR: Display information of the container runtime
\fB\fCinfo\fR: Display information of the container runtime
.IP \(bu 2
\fB\fCstop\fR: Stop one or more running containers
\fB\fCstop\fR: Stop one or more running containers
.IP \(bu 2
\fB\fCstopp\fR: Stop one or more running pods
\fB\fCstopp\fR: Stop one or more running pods
.IP \(bu 2
\fB\fCupdate\fR: Update one or more running containers
\fB\fCupdate\fR: Update one or more running containers
.IP \(bu 2
\fB\fCconfig\fR: Get and set \fB\fCcrictl\fR client configuration options
\fB\fCconfig\fR: Get and set \fB\fCcrictl\fR client configuration options
.IP \(bu 2
\fB\fCstats\fR: List container(s) resource usage statistics
\fB\fCstats\fR: List container(s) resource usage statistics
.IP \(bu 2
\fB\fCstatsp\fR: List pod(s) resource usage statistics
\fB\fCstatsp\fR: List pod(s) resource usage statistics
.IP \(bu 2
\fB\fCcompletion\fR: Output bash shell completion code
\fB\fCcompletion\fR: Output bash shell completion code
.IP \(bu 2
\fB\fCcheckpoint\fR: Checkpoint one or more running containers
\fB\fCcheckpoint\fR: Checkpoint one or more running containers
.IP \(bu 2
\fB\fCevents, event\fR: Stream the events of containers
\fB\fCevents, event\fR: Stream the events of containers
.IP \(bu 2
\fB\fChelp, h\fR: Shows a list of commands or help for one command
\fB\fCupdate\-runtime\-config\fR Update the runtime configuration
.IP \(bu 2
\fB\fChelp, h\fR: Shows a list of commands or help for one command

.RE

Expand Down
63 changes: 32 additions & 31 deletions docs/crictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,38 @@ crictl [global options] command [command options] [arguments...]

COMMANDS:

- `attach`: Attach to a running container
- `create`: Create a new container
- `exec`: Run a command in a running container
- `version`: Display runtime version information
- `images, image, img`: List images
- `inspect`: Display the status of one or more containers
- `inspecti`: Return the status of one or more images
- `imagefsinfo`: Return image filesystem info
- `inspectp`: Display the status of one or more pods
- `logs`: Fetch the logs of a container
- `port-forward`: Forward local port to a pod
- `ps`: List containers
- `pull`: Pull an image from a registry
- `run`: Run a new container inside a sandbox
- `runp`: Run a new pod
- `rm`: Remove one or more containers
- `rmi`: Remove one or more images
- `rmp`: Remove one or more pods
- `pods`: List pods
- `start`: Start one or more created containers
- `info`: Display information of the container runtime
- `stop`: Stop one or more running containers
- `stopp`: Stop one or more running pods
- `update`: Update one or more running containers
- `config`: Get and set `crictl` client configuration options
- `stats`: List container(s) resource usage statistics
- `statsp`: List pod(s) resource usage statistics
- `completion`: Output bash shell completion code
- `checkpoint`: Checkpoint one or more running containers
- `events, event`: Stream the events of containers
- `help, h`: Shows a list of commands or help for one command
- `attach`: Attach to a running container
- `create`: Create a new container
- `exec`: Run a command in a running container
- `version`: Display runtime version information
- `images, image, img`: List images
- `inspect`: Display the status of one or more containers
- `inspecti`: Return the status of one or more images
- `imagefsinfo`: Return image filesystem info
- `inspectp`: Display the status of one or more pods
- `logs`: Fetch the logs of a container
- `port-forward`: Forward local port to a pod
- `ps`: List containers
- `pull`: Pull an image from a registry
- `run`: Run a new container inside a sandbox
- `runp`: Run a new pod
- `rm`: Remove one or more containers
- `rmi`: Remove one or more images
- `rmp`: Remove one or more pods
- `pods`: List pods
- `start`: Start one or more created containers
- `info`: Display information of the container runtime
- `stop`: Stop one or more running containers
- `stopp`: Stop one or more running pods
- `update`: Update one or more running containers
- `config`: Get and set `crictl` client configuration options
- `stats`: List container(s) resource usage statistics
- `statsp`: List pod(s) resource usage statistics
- `completion`: Output bash shell completion code
- `checkpoint`: Checkpoint one or more running containers
- `events, event`: Stream the events of containers
- `update-runtime-config` Update the runtime configuration
- `help, h`: Shows a list of commands or help for one command

`crictl` by default connects on Unix to:

Expand Down
Loading