-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1473 from saschagrunert/update-runtime-config
Add crictl `update-runtime-config` command
- Loading branch information
Showing
4 changed files
with
133 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters