Skip to content

Conversation

@xavier-hou
Copy link
Member

Signed-off-by: hxcGit houxc_mail@163.com

Pre-Checklist

Note: please complete ALL items in the following checklist.

  • I have read through the CONTRIBUTING.md documentation.
  • My code has the necessary comments and documentation (if needed).
  • I have added relevant tests

Description

  • Refactor goclient to plugininstall way
  • zentao plugin has been tested

Related Issues

#850

New Behavior (screenshots if needed)

{22-07-22 21:55}hxc-macbook-air:devstream@refactor-go-client✗✗✗✗✗✗ hxc% ./dtm apply -f zentao.yaml -y --debug 
2022-07-22 21:55:59 ℹ [INFO]  Log level is: debug.
2022-07-22 21:55:59 ℹ [INFO]  Apply started.
2022-07-22 21:55:59 λ [DEBUG]  Original config: 
---
# core config
varFile: ''
toolFile: ''
state: # state config, backend can be local or s3
  backend: local
  options:
    stateFile: devstream.state

---
# plugins config
tools:
  # name of the tool
  - name: zentao
    # id of the tool instance
    instanceID: default
    # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool
    dependsOn: []
    # options for the plugin
    options:
      # namespace for ZenTao application
      namespace: 'zentao'
      # storageClassName used to match pv and pvc
      storageClassName: 'zentao-storage'
      # two PersistentVolumes for ZenTao and mysql should be specified
      persistentVolumes:
          # name of ZenTao pv
        - pvName: "zentao-pv"
          # capacity of ZenTao pv
          pvCapacity: "1G"
          # name of mysql pv
        - pvName: "mysql-pv"
          # capacity of mysql pv
          pvCapacity: "1G"
      # two PersistentVolumeClaims for ZenTao and mysql should be specified
      persistentVolumeClaims:
          # name of ZenTao pvc
        - pvcName: "zentao-pvc"
          # capacity of ZenTao pvc
          pvcCapacity: "1G"
          # name of mysql pvc
        - pvcName: "mysql-pvc"
          # capacity of mysql pvc
          pvcCapacity: "1G"
      # ZenTao application is deployed by K8s Deployment
      deployment:
        # name of ZenTao deployment
        name: 'zentao-dp'
        # number of application replica
        replicas: 1
        # ZenTao image
        image: 'easysoft/zentao:latest'
        env:
          key: 'MYSQL_ROOT_PASSWORD'
          # initial password value for mysql database, you can specify any value you like
          value: '12345678'
      # ZenTao application is exposed via K8s Service
      service:
        # name of ZenTao service
        name: 'zentao-svc'
        # nodePort of ZenTao service, currently ZenTao plugin only support `nodePort` type
        nodePort: 30081


2022-07-22 21:55:59 ℹ [INFO]  Got Backend from config: local
2022-07-22 21:55:59 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-07-22 21:56:00 λ [DEBUG]  The global manager m is not initialized.
2022-07-22 21:56:00 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-07-22 21:56:00 λ [DEBUG]  Used the Backend: local.
2022-07-22 21:56:00 λ [DEBUG]  isForce:false
2022-07-22 21:56:00 λ [DEBUG]  TOOL zentao.default dependency already solved

2022-07-22 21:56:00 λ [DEBUG]  BATCH: [{zentao default [] map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage]}]
2022-07-22 21:56:00 λ [DEBUG]  Changes for the plan:
2022-07-22 21:56:00 λ [DEBUG]  Change - 1/1 -> 
{
  ActionName: Create,
  Tool: {Name: zentao, InstanceID: default}}
}
2022-07-22 21:56:00 ℹ [INFO]  Tool (zentao/default) found in config but doesn't exist in the state, will be created.
2022-07-22 21:56:00 ℹ [INFO]  Start executing the plan.
2022-07-22 21:56:00 ℹ [INFO]  Changes count: 1.
2022-07-22 21:56:00 λ [DEBUG]  TOOL zentao.default dependency already solved

2022-07-22 21:56:00 λ [DEBUG]  BATCH: [{zentao default [] map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage]}]
2022-07-22 21:56:00 ℹ [INFO]  -------------------- [  Processing progress: 1/1.  ] --------------------
2022-07-22 21:56:00 ℹ [INFO]  Processing: (zentao/default) -> Create ...
2022-07-22 21:56:00 λ [DEBUG]  Tool's raw changes are: map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage].
2022-07-22 21:56:00 λ [DEBUG]  Start Execute PreInstall Operations...
2022-07-22 21:56:00 λ [DEBUG]  Start Execute Install Operations...
2022-07-22 21:56:00 λ [DEBUG]  Prepare to create the namespace: zentao.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:00 λ [DEBUG]  The namespace zentao has been created.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:00 λ [DEBUG]  Prepare to create persistentVolume: zentao-pv.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolume < zentao-pv > has created.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolume zentao-pv has been created.
2022-07-22 21:56:00 λ [DEBUG]  Prepare to create persistentVolume: mysql-pv.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolume < mysql-pv > has created.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolume mysql-pv has been created.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:00 λ [DEBUG]  Prepare to create persistentVolumeClaim: zentao-pvc.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeCliam option for creation is &PersistentVolumeClaim{ObjectMeta:{zentao-pvc      0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[] [] []  []},Spec:PersistentVolumeClaimSpec{AccessModes:[ReadWriteOnce],Resources:ResourceRequirements{Limits:ResourceList{},Requests:ResourceList{storage: {{1 9} {<nil>} 1G DecimalSI},},},VolumeName:,Selector:nil,StorageClassName:*zentao-storage,VolumeMode:nil,DataSource:nil,DataSourceRef:nil,},Status:PersistentVolumeClaimStatus{Phase:,AccessModes:[],Capacity:ResourceList{},Conditions:[]PersistentVolumeClaimCondition{},},}
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeClaim < zentao-pvc > has created.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeClaim zentao-pvc has been created.
2022-07-22 21:56:00 λ [DEBUG]  Prepare to create persistentVolumeClaim: mysql-pvc.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeCliam option for creation is &PersistentVolumeClaim{ObjectMeta:{mysql-pvc      0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[] [] []  []},Spec:PersistentVolumeClaimSpec{AccessModes:[ReadWriteOnce],Resources:ResourceRequirements{Limits:ResourceList{},Requests:ResourceList{storage: {{1 9} {<nil>} 1G DecimalSI},},},VolumeName:,Selector:nil,StorageClassName:*zentao-storage,VolumeMode:nil,DataSource:nil,DataSourceRef:nil,},Status:PersistentVolumeClaimStatus{Phase:,AccessModes:[],Capacity:ResourceList{},Conditions:[]PersistentVolumeClaimCondition{},},}
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeClaim < mysql-pvc > has created.
2022-07-22 21:56:00 λ [DEBUG]  The PersistentVolumeClaim mysql-pvc has been created.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:00 λ [DEBUG]  The Deployment zentao-dp has been created.
2022-07-22 21:56:00 λ [DEBUG]  The Deployment zentao-dp has been created.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:00 λ [DEBUG]  The Service zentao-svc has been created.
2022-07-22 21:56:00 λ [DEBUG]  The Service zentao-svc has been created.
2022-07-22 21:56:00 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:05 λ [DEBUG]  Retry check deployment status 0 times
2022-07-22 21:56:05 ℹ [INFO]  The deployment zentao-dp is ready.
2022-07-22 21:56:05 λ [DEBUG]  Start Execute Status Operations...
2022-07-22 21:56:05 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:05 λ [DEBUG]  The deployment zentao-dp is ready.
2022-07-22 21:56:05 λ [DEBUG]  The service zentao-svc is ready.
2022-07-22 21:56:05 λ [DEBUG]  Start -> StatesMap now is:

2022-07-22 21:56:05 ✔ [SUCCESS]  Tool (zentao/default) Create done.
2022-07-22 21:56:05 λ [DEBUG]  End -> StatesMap now is:
zentao_default:
  name: zentao
  instanceid: default
  dependson: []
  options:
    deployment:
      env:
        key: MYSQL_ROOT_PASSWORD
        value: "12345678"
      image: easysoft/zentao:latest
      name: zentao-dp
      replicas: 1
    namespace: zentao
    persistentVolumeClaims:
      - pvcCapacity: 1G
        pvcName: zentao-pvc
      - pvcCapacity: 1G
        pvcName: mysql-pvc
    persistentVolumes:
      - pvCapacity: 1G
        pvName: zentao-pv
      - pvCapacity: 1G
        pvName: mysql-pv
    service:
      name: zentao-svc
      nodePort: 30081
    storageClassName: zentao-storage
  resource:
    running: true

2022-07-22 21:56:05 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-07-22 21:56:05 ✔ [SUCCESS]  All plugins applied successfully.
2022-07-22 21:56:05 ✔ [SUCCESS]  Apply finished.
{22-07-22 21:56}hxc-macbook-air:devstream@refactor-go-client✗✗✗✗✗✗ hxc% ./dtm delete -f zentao.yaml -y --debug
2022-07-22 21:56:12 ℹ [INFO]  Log level is: debug.
2022-07-22 21:56:12 ℹ [INFO]  Delete started.
2022-07-22 21:56:12 λ [DEBUG]  Original config: 
---
# core config
varFile: ''
toolFile: ''
state: # state config, backend can be local or s3
  backend: local
  options:
    stateFile: devstream.state

---
# plugins config
tools:
  # name of the tool
  - name: zentao
    # id of the tool instance
    instanceID: default
    # format: name.instanceID; If specified, dtm will make sure the dependency is applied first before handling this tool
    dependsOn: []
    # options for the plugin
    options:
      # namespace for ZenTao application
      namespace: 'zentao'
      # storageClassName used to match pv and pvc
      storageClassName: 'zentao-storage'
      # two PersistentVolumes for ZenTao and mysql should be specified
      persistentVolumes:
          # name of ZenTao pv
        - pvName: "zentao-pv"
          # capacity of ZenTao pv
          pvCapacity: "1G"
          # name of mysql pv
        - pvName: "mysql-pv"
          # capacity of mysql pv
          pvCapacity: "1G"
      # two PersistentVolumeClaims for ZenTao and mysql should be specified
      persistentVolumeClaims:
          # name of ZenTao pvc
        - pvcName: "zentao-pvc"
          # capacity of ZenTao pvc
          pvcCapacity: "1G"
          # name of mysql pvc
        - pvcName: "mysql-pvc"
          # capacity of mysql pvc
          pvcCapacity: "1G"
      # ZenTao application is deployed by K8s Deployment
      deployment:
        # name of ZenTao deployment
        name: 'zentao-dp'
        # number of application replica
        replicas: 1
        # ZenTao image
        image: 'easysoft/zentao:latest'
        env:
          key: 'MYSQL_ROOT_PASSWORD'
          # initial password value for mysql database, you can specify any value you like
          value: '12345678'
      # ZenTao application is exposed via K8s Service
      service:
        # name of ZenTao service
        name: 'zentao-svc'
        # nodePort of ZenTao service, currently ZenTao plugin only support `nodePort` type
        nodePort: 30081


2022-07-22 21:56:12 ℹ [INFO]  Got Backend from config: local
2022-07-22 21:56:12 ℹ [INFO]  Using dir <.devstream> to store plugins.
2022-07-22 21:56:12 λ [DEBUG]  The global manager m is not initialized.
2022-07-22 21:56:12 ℹ [INFO]  Using local backend. State file: devstream.state.
2022-07-22 21:56:12 λ [DEBUG]  Used the Backend: local.
2022-07-22 21:56:12 λ [DEBUG]  Got a state from the backend: zentao_default -> {zentao default [] map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage] map[running:true]}.
2022-07-22 21:56:12 λ [DEBUG]  isForce:false
2022-07-22 21:56:12 λ [DEBUG]  TOOL zentao.default dependency already solved

2022-07-22 21:56:12 λ [DEBUG]  BATCH: [{zentao default [] map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage]}]
2022-07-22 21:56:12 λ [DEBUG]  Changes for the plan:
2022-07-22 21:56:12 λ [DEBUG]  Change - 1/1 -> 
{
  ActionName: Delete,
  Tool: {Name: zentao, InstanceID: default}}
}
2022-07-22 21:56:12 ℹ [INFO]  Tool (zentao/default) will be deleted.
2022-07-22 21:56:12 ℹ [INFO]  Start executing the plan.
2022-07-22 21:56:12 ℹ [INFO]  Changes count: 1.
2022-07-22 21:56:12 λ [DEBUG]  TOOL zentao.default dependency already solved

2022-07-22 21:56:12 λ [DEBUG]  BATCH: [{zentao default [] map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage]}]
2022-07-22 21:56:12 ℹ [INFO]  -------------------- [  Processing progress: 1/1.  ] --------------------
2022-07-22 21:56:12 ℹ [INFO]  Processing: (zentao/default) -> Delete ...
2022-07-22 21:56:12 λ [DEBUG]  Tool's raw changes are: map[deployment:map[env:map[key:MYSQL_ROOT_PASSWORD value:12345678] image:easysoft/zentao:latest name:zentao-dp replicas:1] namespace:zentao persistentVolumeClaims:[map[pvcCapacity:1G pvcName:zentao-pvc] map[pvcCapacity:1G pvcName:mysql-pvc]] persistentVolumes:[map[pvCapacity:1G pvName:zentao-pv] map[pvCapacity:1G pvName:mysql-pv]] service:map[name:zentao-svc nodePort:30081] storageClassName:zentao-storage].
2022-07-22 21:56:12 λ [DEBUG]  Start Execute PreInstall Operations...
2022-07-22 21:56:12 λ [DEBUG]  Start Execute Install Operations...
2022-07-22 21:56:12 λ [DEBUG]  Failed to get the kubecondig from env. Prepare to get it from home dir.
2022-07-22 21:56:12 λ [DEBUG]  Prepare to delete PVC.
2022-07-22 21:56:12 λ [DEBUG]  Prepare to delete PV.
2022-07-22 21:56:12 λ [DEBUG]  Prepare to delete namespace.
2022-07-22 21:56:13 λ [DEBUG]  Start -> StatesMap now is:
zentao_default:
  name: zentao
  instanceid: default
  dependson: []
  options:
    deployment:
      env:
        key: MYSQL_ROOT_PASSWORD
        value: "12345678"
      image: easysoft/zentao:latest
      name: zentao-dp
      replicas: 1
    namespace: zentao
    persistentVolumeClaims:
      - pvcCapacity: 1G
        pvcName: zentao-pvc
      - pvcCapacity: 1G
        pvcName: mysql-pvc
    persistentVolumes:
      - pvCapacity: 1G
        pvName: zentao-pv
      - pvCapacity: 1G
        pvName: mysql-pv
    service:
      name: zentao-svc
      nodePort: 30081
    storageClassName: zentao-storage
  resource:
    running: true

2022-07-22 21:56:13 ℹ [INFO]  Prepare to delete 'zentao_default' from States.
2022-07-22 21:56:13 ✔ [SUCCESS]  Tool (zentao/default) delete done.
2022-07-22 21:56:13 λ [DEBUG]  End -> StatesMap now is:

2022-07-22 21:56:13 ℹ [INFO]  -------------------- [  Processing done.  ] --------------------
2022-07-22 21:56:13 ✔ [SUCCESS]  All plugins deleted successfully.
2022-07-22 21:56:13 ✔ [SUCCESS]  Delete finished.

@xavier-hou xavier-hou requested review from a team and IronCore864 as code owners July 22, 2022 14:02
Copy link

@steinliber steinliber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this refactor is elegant

Signed-off-by: hxcGit <houxc_mail@163.com>
@xavier-hou xavier-hou force-pushed the refactor-go-client branch from 7af50ef to f3ca0bb Compare July 24, 2022 09:01
Signed-off-by: hxcGit <houxc_mail@163.com>
@xavier-hou xavier-hou requested review from iyear and steinliber July 25, 2022 03:47
@iyear
Copy link
Member

iyear commented Jul 25, 2022

Nice refactoring! If the test passes again, it can be merged.

Signed-off-by: hxcGit <houxc_mail@163.com>
@IronCore864 IronCore864 merged commit 71c06f8 into devstream-io:main Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants