英文:
Changing the Deployment Strategy from RollingUpdate to Recreate using Golang
问题
我有一个非常大的问题。我们有大量的部署使用的组件,直到现在都使用的是RollingUpdate部署策略类型。
spec:
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
现在一个新的设计决策需要我们将其移动到Recreate
策略,如果我们可以编写一个shell脚本来调用kubectl patch
并使用文档中描述的$retainKeys
方法,那将会相当容易。
然而,我们使用的是用Golang编写的自定义工具来管理我们的大量部署,我们希望将其集成到我们的常规更新周期中,并避免使用这种hack。因此,我已经将代码更改为以下形式:
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"
但是,有没有人能够告诉我如何在我的Golang结构体/代码中指定retainKeys
列表?非常感谢!
英文:
I have a very big issue. We have a large number of deployments for a component which up until now were using the RollingUpdate deployment strategy type.
spec:
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
Now a new design decision needs us to move this to a Recreate
strategy, which would be fairly easy if we could just write a shell script to call kubectl patch
and use the $retainKeys
method described in the docs.
However, we use a custom tool written in Golang to manage our gazillion deployments and we'd like to integrate this into our regular update cycle and avoid this hack. Therefore, I've changed the code to look like this:
deploy := &appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Strategy: appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
Obviously, when we run the update procedure, the tool fails with the following error:
Error updating *v1.Deployment Deployment.apps "cluster-agent" is invalid: spec.strategy.rollingUpdate: Forbidden: may not be specified when strategy `type` is 'Recreate'
According to the above link, the retainKeys
trick has to be used but I have not managed to find out how that can be done from within Golang.
I can see in the k8s api sources that the patch strategy supports the retainKeys method:
Strategy DeploymentStrategy `json:"strategy,omitempty" patchStrategy:"retainKeys"
But would someone be so kind as to let me know how can I specify the retainKeys
list within my Golang structs/code? Thank you very much!
答案1
得分: 3
这个问题的最新更新有效。
strategy:
rollingUpdate: null
type: Recreate
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论