在openshift / kubernetes中创建yaml模板来创建组并通过列表传递用户

2hh7jdfx  于 2023-10-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(125)

我需要添加几个用户到一个新的组模板

apiVersion: template.openshift.io/v1
kind: Template
metadata:
  name: group-devops-template
objects:
- apiVersion: user.openshift.io/v1
  kind: Group
  metadata:
    name: ${GROUP_NAME}
  users: ["${USER_NAMES}"] # <--- here the issue
  #- user1
  #- user2
  #- user3
parameters:
- name: GROUP_NAME
  description: Password used for Redis authentication

- name: USER_NAMES
  description: user or users to add

当我用值处理模板时,噩梦就发生了。

oc process -f grup_template3 -p GROUP_NAME=admin_devops  -p USER_NAMES=["user1","user2","user3"]  | oc create -f -

我的问题是:

  • 如何在上述模板中正确指定列表
  • 如何正确指定值列表:[“user1”,“user2”,“user3”]

最后一个用户组应该是这样的:

oc get groups admin_devops -o yaml
apiVersion: user.openshift.io/v1
kind: Group
metadata:
  name: admin_devops
users:
- user1
- user2
- user3

你有什么办法实现这一目标吗?

z9ju0rcb

z9ju0rcb1#

你的用户var应该写为${{USER_NAMES}USER_NAMES var应该格式化为正确的yaml。下面是工作示例:

template.yaml

apiVersion: template.openshift.io/v1
kind: Template
metadata:
  name: group-devops-template
objects:
- apiVersion: user.openshift.io/v1
  kind: Group
  metadata:
    name: ${GROUP_NAME}
  users: ${{USER_NAMES}}
parameters:
- name: GROUP_NAME
  description: Password used for Redis authentication
- name: USER_NAMES
  description: user or users to add

命令:

oc process -f template.yaml -p GROUP_NAME=admin_devops  -p USER_NAMES='["user1","user2","user3"]' --local=true -o yaml

输出:

apiVersion: v1
items:
- apiVersion: user.openshift.io/v1
  kind: Group
  metadata:
    name: admin_devops
  users:
  - user1
  - user2
  - user3
kind: List
metadata: {}

相关问题