go - 将部署策略从 RollingUpdate 更改为使用 Golang 重新创建
问题描述
我有一个很大的问题。我们有大量的组件部署,到目前为止,这些组件都使用 RollingUpdate 部署策略类型。
spec:
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
现在一个新的设计决策需要我们将其转移到一个Recreate
策略中,如果我们可以编写一个 shell 脚本来调用kubectl patch
和使用文档中描述$retainKeys
的方法,这将是相当容易的。
但是,我们使用用 Golang 编写的自定义工具来管理我们的海量部署,我们希望将其集成到我们的常规更新周期中并避免这种黑客攻击。因此,我将代码更改为如下所示:
deploy := &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
显然,当我们运行更新程序时,该工具失败并出现以下错误:
Error updating *v1.Deployment Deployment.apps "cluster-agent" is invalid: spec.strategy.rollingUpdate: Forbidden: may not be specified when strategy `type` is 'Recreate'
根据上面的链接,retainKeys
必须使用该技巧,但我还没有设法从 Golang 中找出如何做到这一点。
我可以在k8s api源中看到补丁策略支持retainKeys方法:
Strategy DeploymentStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys"
但是有人会好心让我知道如何retainKeys
在我的 Golang 结构/代码中指定列表吗?非常感谢!
解决方案
推荐阅读
- javascript - 为什么我的 Bootstrap 手风琴不能正常工作?
- python-3.x - 使用 cython 时出错“致命错误 C1083;无法打开包含文件:'io.h':没有这样的文件或目录”
- swift - 在 Swift 中异步合并两个字典
- c++ - 如何将int转换为字符串?
- angular - Nativescript - 装饰器不支持错误函数调用,但调用了“NativeScriptRouterModule”
- java - 如何使用 Spring Boot 将 @Cacheable 与 redis 一起使用
- nginx - 反向代理到两个单独的 nginx 实例
- node.js - 如何配置 rollupJs 将 nodeJs 脚本转换为 es6 模块?
- javascript - 在JS中使用按钮点击制作变量
- python - 如何在 Python 中使用 zip 函数并返回包含最大值的系列的索引?