-- Topology agent와 Metric agent 통합 작업
UPDATE public.agent_install_file_info
	SET yaml='---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cloudmoa-cluster-role
rules:
  - nonResourceURLs:
      - "*"
    verbs:
      - get
  - apiGroups:
      - metrics.k8s.io
    resources:
      - pods
      - nodes
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - pods
    verbs:
      - get
      - list
      - watch
      - update
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - watch
      - update
  - apiGroups:
      - ""
    resources:
      - nodes/stats
      - endpoints
      - namespaces
      - events
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - apps
    resources:
      - daemonsets
      - deployments
      - deployments/scale
      - replicasets
      - replicasets/scale
      - statefulsets
      - statefulsets/scale
    verbs:
      - get
      - list
      - watch
      - update
  - apiGroups:
      - batch
    resources:
      - jobs
    verbs:
      - get
      - list
      - watch
      - update
  - apiGroups:
      - batch
    resources:
      - cronjobs
    verbs:
      - get
      - list
      - update
  - apiGroups:
      - storage.j8s.io
    resources:
      - storageclasses
    verbs:
      - get
      - list
  - apiGroups:
      - networking.k8s.io
    resources:
      - ingresses
    verbs:
      - get
      - list
  - apiGroups:
      - extensions
    resources:
      - ingresses
    verbs:
      - get
      - list
  - apiGroups:
      - policy
    resources:
      - podsecuritypolicies
    verbs:
      - use
    resourceNames:
      - imxc-ps
  - apiGroups:
      - certificates.k8s.io
    resourceNames:
      - kubernetes.io/kube-apiserver-client-kubelet
    resources:
      - signers
    verbs:
      - approve
  - apiGroups:
      - certificates.k8s.io
    resourceNames:
      - kubernetes.io/kubelet-serving
    resources:
      - signers
    verbs:
      - approve
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
      - proxy
  - apiGroups:
      - ""
    resources:
      - nodes/log
      - nodes/metrics
      - nodes/proxy
      - nodes/spec
      - nodes/stats
    verbs:
      - ''*''
  - apiGroups:
      - ''*''
    resources:
      - ''*''
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cloudmoa-restricted-rb
  namespace: $CLOUDMOA_NAMESPACE
subjects:
  - kind: ServiceAccount
    name: default
    namespace: $CLOUDMOA_NAMESPACE
roleRef:
  kind: ClusterRole
  name: cloudmoa-cluster-role
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: cloudmoa-psp
  namespace: $CLOUDMOA_NAMESPACE
spec:
  privileged: true
  seLinux:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  runAsUser:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  hostPorts:
    - max: 65535
      min: 0
  hostNetwork: true
  hostPID: true
  volumes:
    - configMap
    - secret
    - emptyDir
    - hostPath
    - projected
    - downwardAPI
    - persistentVolumeClaim
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cloudmoa-topology-agent
  namespace: $CLOUDMOA_NAMESPACE
  labels:
    app: cloudmoa-topology-agent
spec:
  selector:
    matchLabels:
      app: cloudmoa-topology-agent
  template:
    metadata:
      labels:
        app: cloudmoa-topology-agent
    spec:
      hostNetwork: true
      hostPID: true
      tolerations:
      - effect: NoSchedule
        operator: Exists
      - effect: NoExecute
        operator: Exists
      containers:
      - name: metric-agent
        image: $DOCKER_REGISTRY_URL/metric-agent:$IMAGE_TAG
        args:
          - --config.file=/etc/metric-agent/metric-agent.yml
        env:
          - name: CLUSTER_ID
            value: $CLOUDMOA_CLUSTER_ID
          - name: STORAGE_TYPE
            value: datagate
          - name: DATAGATE
            value: $COLLTION_SERVER_DATAGATE_IP:$COLLTION_SERVER_DATAGATE_PORT
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: spec.nodeName
          - name: LOG_LEVEL
            value: "INFO"
        ports:
          - containerPort: 14271
            protocol: TCP
          - containerPort: 14272
            protocol: TCP
        resources:
          limits:
            cpu: 250m
            memory: 180Mi
          requests:
            cpu: 125m
            memory: 90Mi
        volumeMounts:
          - mountPath: /etc/metric-agent/
            name: config-volume
      - image: $DOCKER_REGISTRY_URL/node-exporter
        name: node-agent
        resources:
          limits:
            cpu: 250m
            memory: 180Mi
          requests:
            cpu: 125m
            memory: 90Mi
        ports:
        - containerPort: 9110
          hostPort: 9110
          name: scrape
        args:
        - --path.procfs=/host/proc
        - --path.sysfs=/host/sys
        - --path.rootfs=/host/root
        - --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|run|var/lib/docker/.+|var/lib/kubelet/pods/.+)($|/)
        - --collector.tcpstat
        - --web.listen-address=:9110
        # --log.level=debug
        env:
        - name: GOMAXPROCS
          value: "1"
        volumeMounts:
        - mountPath: /host/proc
          name: proc-volume
          readOnly: false
        - mountPath: /host/sys
          name: sys-volume
          readOnly: false
        - mountPath: /host/root
          mountPropagation: HostToContainer
          name: root-volume
          readOnly: true
      - name: cloudmoa-topology-agent
        image: $DOCKER_REGISTRY_URL/topology-agent:$IMAGE_TAG
        resources:
          requests:
            cpu: 200m
            memory: 512Mi
          limits:
            cpu: 500m
            memory: 600Mi
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /host/usr/bin
          name: bin-volume
        - mountPath: /var/run/docker.sock
          name: docker-volume
        - mountPath: /host/proc
          name: proc-volume
        - mountPath: /root
          name: root-volume
        - mountPath: /log
          name: log-volume
        env:
          - name: DATAGATE
            value: $COLLTION_SERVER_DATAGATE_IP:$COLLTION_SERVER_DATAGATE_PORT
          - name: CLUSTER_ID
            value: $CLOUDMOA_CLUSTER_ID
          - name: ROOT_DIRECTORY
            value: /root
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: spec.nodeName
          - name: POD_ID
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: LOG_LEVEL
            value: "INFO"
        livenessProbe:
          httpGet:
            path: /healthz
            port: 18081
          initialDelaySeconds: 30
          timeoutSeconds: 5
      volumes:
      - name: bin-volume
        hostPath:
          path: /usr/bin
          type: Directory
      - name: docker-volume
        hostPath:
          path: /var/run/docker.sock
      - name: proc-volume
        hostPath:
          path: /proc
      - name: root-volume
        hostPath:
          path: /
      - hostPath:
          path: /sys
        name: sys-volume
      - name: log-volume
        hostPath:
          path: /home'
	WHERE id=2;


-- Analysis|Log Viewer 에 Container Tab 추가
INSERT INTO public.auth_resource3 (name, is_deleted, tenant_id) VALUES ('menu|Statistics & Analysis|Log Viewer|Container', false, null);
INSERT INTO public.menu_meta (id, description, icon, "position", url, auth_resource3_id, scope_level) VALUES (53, 'Log Viewer(Container)', NULL, 13, '', (select id from auth_resource3 where name='menu|Statistics & Analysis|Log Viewer|Container'), 0);
commit;

