5.6.4. 为较新的 Operator SDK 版本更新项目


OpenShift Container Platform 4.12 支持 Operator SDK 1.25.4。如果您已在工作站上安装了 1.22.2 CLI,您可以通过安装最新版本将 CLI 更新至 1.25.4。

但是,要确保现有 Operator 项目保持与 Operator SDK 1.25.4 的兼容性,需要执行更新的相关步骤才能解决自 1.22.2 的变化可能造成的问题。您必须在之前使用 1.22.2 创建或维护的任何 Operator 项目中手动执行更新步骤。

以下流程更新了基于 Java 的 Operator 项目,以便与 1.25.4 兼容。

先决条件

  • 已安装 operator SDK 1.25.4
  • 使用 Operator SDK 1.22.2 创建或维护的 Operator 项目

流程

  1. config/default/manager_auth_proxy_patch.yaml 文件进行以下更改:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: controller-manager
      namespace: system
    spec:
      template:
        spec:
          containers:
          - name: kube-rbac-proxy
            image: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.12 
    1
    
            args:
            - "--secure-listen-address=0.0.0.0:8443"
            - "--upstream=http://127.0.0.1:8080/"
            - "--logtostderr=true"
            - "--v=0"
    ...
    1
    将标签版本从 v4.11 更新至 v4.12
  2. Makefile 进行以下更改:

    1. 要启用多架构构建支持,请将 docker-buildx 目标添加到项目的 Makefile 中:

      Makefile示例

      # PLATFORMS defines the target platforms for  the manager image be build to provide support to multiple
      # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
      # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
      # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
      # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
      # To properly provided solutions that supports more than one platform you should use this option.
      PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
      .PHONY: docker-buildx
      docker-buildx: test ## Build and push docker image for the manager for cross-platform support
      	# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
      	sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
      	- docker buildx create --name project-v3-builder
      	docker buildx use project-v3-builder
      	- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
      	- docker buildx rm project-v3-builder
      	rm Dockerfile.cross

    2. 要将更改应用到 Makefile 并重建 Operator,请输入以下命令:

      $ make
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部