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

doc: seamless crds upgrade #434

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions docs/user-manuals/crd-upgrade/yurtmanager-crd-upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: seamless CRDs upgrade
---

## Brackgound introduction

There is no support at this time for upgrading Custom Resource Definitions (CRDs) using Helm. This was an explicit decision after much community discussion due to the danger for unintentional data loss. Furthermore, there is currently no community consensus around how to handle CRDs and their lifecycle.

As a consequence, it is necessary to manually apply to update CRDs one by one. It is troublesome and the upgrade process should be automated.

## Automation Implementation
Init containers can contain utilities or setup scripts not present in an app image.
We can utilize init container to upgrade CRDs. We can copy all CRDs related files into images and iterate through each crd yaml to update the crd using server side apply, as follows:

```go
filepath.Walk(CRD_DIR, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
switch {
case info.Mode().IsDir():
return nil
case info.Mode().IsRegular():
// ...
// client apply crd to upgrade
}
return nil
})
```

## How to use

Using yurt-manager as an example, we only need to copy the binary in and execute it in the command.

```yaml
initContainers:
- image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
name: crd-upgrader
imagePullPolicy: IfNotPresent
command:
- /usr/local/bin/crd-upgrader
```

We also should make sure to provide CRD-related permissions to the service account.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: 无缝升级CRDs
---

## 背景介绍

目前不支持使用Helm升级或删除CRDs。由于数据意外丢失的风险,这是经过多次社区讨论后作出的明确决定。对于如何处理CRD及其生命周期, 目前社区还未达成共识。

因此,用户必须逐个手动申请更新CRDs。这是一件很繁琐的事情,升级过程应该自动化。

## 自动化实现
Init容器可以包含应用程序镜像中不存在的实用工具和安装脚本。
我们可以利用Init容器升级 CRD。我们可以将所有与 CRD 相关的文件复制到映像中,然后遍历每个crd yaml,使用服务器端应用更新 crd,如下所示:

```go
filepath.Walk(CRD_DIR, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
switch {
case info.Mode().IsDir():
return nil
case info.Mode().IsRegular():
// ...
// client apply crd to upgrade
}
return nil
})
```

## 如何使用

以 yurt-manager 为例,我们只需复制二进制文件并在命令中执行即可。

```yaml
initContainers:
- image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
name: crd-upgrader
imagePullPolicy: IfNotPresent
command:
- /usr/local/bin/crd-upgrader
```

需要注意的是,我们还应确保为服务账户提供与 CRD 相关的权限。
5 changes: 5 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ module.exports = {
'IOT': [
'user-manuals/iot/edgex-foundry',
]
},
{
'crd-upgrade': [
'user-manuals/crd-upgrade/yurtmanager-crd-upgrade',
]
}
]
},
Expand Down