Skip to content

Commit

Permalink
Add crictl update-runtime-config command
Browse files Browse the repository at this point in the history
The command can be used to update the runtime config, which only
supports the pod CIDR for now.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jul 2, 2024
1 parent 254cea5 commit 305210d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 31 deletions.
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
},
}
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

0 comments on commit 305210d

Please sign in to comment.