在 ConfigMap Data 部分从 yaml 创建 pod

问题描述

我正在编写一个通过 yaml 部署应用程序的操作符。但是这个 yaml 存储在 ConfigMap 的 data 部分 -

apiVersion: v1
kind: ConfigMap
Metadata:
  name: test-config
  namespace: default
data:
  hstr-opeartor.yaml: |
    apiVersion: apps/v1
    kind: Deployment
    Metadata:
      name: 'hstr-operator'
      namespace: 'cloudian'
    spec:
      replicas: 1
      selector:
        matchLabels:
          name: 'hyperstore-operator'
      template:
        Metadata:
          labels:
            name: 'hyperstore-operator'
        spec:
          containers:
          - args:
            - --enable-leader-election
            command:
            - hyperstore-operator
            env:
            - name: REBUILD_TIMER_emm
              value: "360"
            - name: REBUILD_TIMER_NODE
              value: "360"
            - name: REBUILD_TIMER_PVC
              value: "60"
            - name: IMAGE_PULL_SECRETS
              value: 'hyperstore-regcred'
            - name: IMAGE_HSC
              value: quay.io/cldn/test-image-v2
            - name: WATCH_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldpath: Metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldpath: Metadata.name
            - name: OPERATOR_NAME
              value: hyperstore-operator
            - name: IMAGE_PULL_POLICY
              value: IfNotPresent
            image: quay.io/cldn/test-image
            imagePullPolicy: IfNotPresent
            name: hyperstore-operator
            resources:
              limits:
                cpu: 100m
                memory: 1Gi
              requests:
                cpu: 100m
                memory: 500Mi
          imagePullSecrets:
          - name: 'hyperstore-regcred'
          terminationGracePeriodSeconds: 30

对 yaml 进行了精简,以提供有关该问题的足够多的信息。但实际上这是一个完整的部署文件,我可以用它kubectl apply -f <resource>

// newPodForCR returns a busyBox pod with the same name/namespace as the cr
func newPodForCR(cr *hapv1alpha1.Hscoperator) *corev1.Pod {
    labels := map[string]string{
        "app": cr.Name,}
    return &corev1.Pod{
        ObjectMeta: Metav1.ObjectMeta{
            Name:      cr.Name + "-pod",Namespace: "default",Labels:    labels,},Spec: corev1.PodSpec{
            Containers: []corev1.Container{
                {
                    Name:  cr.Name,Image: cr.Spec.Image,}
}

在我的操作员的控制器代码中,我确保创建了 ConfigMap。但是现在我想获取这个 configmap 的数据部分并使用 yaml 创建一个新的 pod。我如何在 go 中读取并创建一个新的 pod?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)