mirror of
https://gitee.com/devstar/devstar-devcontainer-operator
synced 2025-04-21 09:42:22 +00:00
!2 CRD status Reporter + CI Workflow Test
* Added CI workflow for Dockerized k8s Operator * Added Readiness Listener based on StatefulSet.Status.ReadyReplicas * Update Readiness Probing timeout mechanism
This commit is contained in:
parent
c10befe9f8
commit
a923904e3b
54
.gitea/workflows/devstar-devcontainer-operator-ci.yaml
Normal file
54
.gitea/workflows/devstar-devcontainer-operator-ci.yaml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#
|
||||||
|
# Add secrets of Remote Git Repository Panel:
|
||||||
|
# - ${{ secrets.DOCKER_REGISTRY_USERNAME }}: username of Docker Registry
|
||||||
|
# - ${{ secrets.DOCKER_REGISTRY_PASSWORD }}: password corresponding to the Docker Registry username
|
||||||
|
|
||||||
|
# Add variables of Remote Git Repository Panel:
|
||||||
|
# - ${{ vars.DOCKER_REGISTRY_ADDRESS }}: the address for Docker Registry
|
||||||
|
# - ${{ vars.DOCKER_REPOSITORY_ARTIFACT}}: the artifact $name:$version, e.g., `devstar/devcontainer-operator:build`
|
||||||
|
|
||||||
|
# 特别注意:如果使用 devstar.cn 作为 Docker Registry,需要设置 Gitea Actions Runner 变量 DOCKER_REGISTRY_ADDRESS = www.devstar.cn,若没有www前缀会导致上传失败(Ingress重定向规则导致,暂时无解)
|
||||||
|
# 上传 Artifact 必须加上 www前缀,而拉取时不需要加 www 前缀,例如:
|
||||||
|
# 上传前 artifact 名称: docker push www.devstar.cn/devstar/devcontainer-operator:build-0047d315a3f73cca0c18c641d24b0347456618d5
|
||||||
|
# 拉取 artifact 只需要: docker pull devstar.cn/devstar/devcontainer-operator:build-0047d315a3f73cca0c18c641d24b0347456618d5
|
||||||
|
|
||||||
|
name: DevStar DevContainer Operator CI Pipeline - main branch
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-x86-64-docker-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 🔍 Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: main
|
||||||
|
- name: 🔧 Build an Artifact
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} ${{ vars.DOCKER_REGISTRY_ADDRESS }} --password-stdin
|
||||||
|
make docker-build docker-push IMG=${{ vars.DOCKER_REGISTRY_ADDRESS }}/${{ vars.DOCKER_REPOSITORY_ARTIFACT }}-${{ gitea.sha }}
|
||||||
|
- name: 🍏 Job Status Report
|
||||||
|
run: |
|
||||||
|
echo "🍏 This job's status is ${{ job.status }}."
|
||||||
|
echo "Output Artifact: ${{ vars.DOCKER_REGISTRY_ADDRESS }}/${{ vars.DOCKER_REPOSITORY_ARTIFACT }}-${{ gitea.sha }}"
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# P.S.:
|
||||||
|
################################################################################
|
||||||
|
# 1. How to config runner:
|
||||||
|
# $ docker run \
|
||||||
|
# --name gitea-act-runner-repo-devcontainer-operator \
|
||||||
|
# -d \
|
||||||
|
# -e GITEA_INSTANCE_URL=https://www.devstar.cn \
|
||||||
|
# -e GITEA_RUNNER_REGISTRATION_TOKEN=${YOUR_GITEA_RUNNER_REGISTRATION_TOKEN} \
|
||||||
|
# -v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
|
# gitea/act_runner:latest
|
||||||
|
#
|
||||||
|
# 2. To clean the docker cache:
|
||||||
|
# $ docker builder prune --force
|
||||||
|
# $ if [ "$(docker volume ls -qf dangling=true)" ]; then docker volume rm $(docker volume ls -qf dangling=true); fi
|
||||||
|
#
|
@ -98,6 +98,10 @@ type DevcontainerAppStatus struct {
|
|||||||
// NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
// NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
||||||
// +optional
|
// +optional
|
||||||
NodePortAssigned uint16 `json:"nodePortAssigned"`
|
NodePortAssigned uint16 `json:"nodePortAssigned"`
|
||||||
|
|
||||||
|
// Ready 标识 DevcontainerApp 管理的 Pod 的 Readiness Probe 是否达到就绪状态
|
||||||
|
// +optional
|
||||||
|
Ready bool `json:"ready"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:object:root=true
|
// +kubebuilder:object:root=true
|
||||||
|
@ -153,6 +153,9 @@ spec:
|
|||||||
nodePortAssigned:
|
nodePortAssigned:
|
||||||
description: NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
description: NodePortAssigned 存储 DevcontainerApp CRD调度后集群分配的 NodePort
|
||||||
type: integer
|
type: integer
|
||||||
|
ready:
|
||||||
|
description: Ready 标识 DevcontainerApp 管理的 Pod 的 Readiness Probe 是否达到就绪状态
|
||||||
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
type: object
|
type: object
|
||||||
served: true
|
served: true
|
||||||
|
@ -86,6 +86,23 @@ func (r *DevcontainerAppReconciler) Reconcile(ctx context.Context, req ctrl.Requ
|
|||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// 若 StatefulSet.Status.readyReplicas 变化,则更新 DevcontainerApp.Status.Ready 域(mark/un-mark)
|
||||||
|
if statefulSetInNamespace.Status.ReadyReplicas > 0 {
|
||||||
|
app.Status.Ready = true
|
||||||
|
if err := r.Status().Update(ctx, app); err != nil {
|
||||||
|
logger.Error(err, "Failed to update DevcontainerApp.Status.Ready", "DevcontainerApp.Status.Ready", app.Status.Ready)
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("DevContainer is now ready", "ReadyReplicas", statefulSetInNamespace.Status.ReadyReplicas)
|
||||||
|
} else {
|
||||||
|
app.Status.Ready = false
|
||||||
|
if err := r.Status().Update(ctx, app); err != nil {
|
||||||
|
logger.Error(err, "Failed to un-mark DevcontainerApp.Status.Ready", "DevcontainerApp.Status.Ready", app.Status.Ready)
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
logger.Info("DevContainer is NOT ready", "ReadyReplicas", statefulSetInNamespace.Status.ReadyReplicas)
|
||||||
|
}
|
||||||
|
|
||||||
// 这里会反复触发更新
|
// 这里会反复触发更新
|
||||||
// 原因:在 SetupWithManager方法中,监听了 StatefulSet ,所以只要更新 StatefulSet 就会触发
|
// 原因:在 SetupWithManager方法中,监听了 StatefulSet ,所以只要更新 StatefulSet 就会触发
|
||||||
// 此处更新和 controllerManager 更新 StatefulSet 都会触发更新事件,导致循环触发
|
// 此处更新和 controllerManager 更新 StatefulSet 都会触发更新事件,导致循环触发
|
||||||
|
@ -51,6 +51,11 @@ spec:
|
|||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- exec cat /etc/ssh/ssh_host*.pub
|
- exec cat /etc/ssh/ssh_host*.pub
|
||||||
|
failureThreshold: 6
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
periodSeconds: 10
|
||||||
|
successThreshold: 1
|
||||||
|
timeoutSeconds: 5
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 300m
|
cpu: 300m
|
||||||
|
Loading…
Reference in New Issue
Block a user