Skip to content

Resource structure, Locking and Unlocking with apiserver

Amit Malav edited this page Aug 2, 2018 · 1 revision

Resource groups:

  • Deployments
    • Director
    • Docker
  • Backup
    • DefaultBackup
  • Lock
    • DeploymentLock
  • Bind
    • DirectorBind
    • DockerBind

Data Structure of resources:

Director:

Schema

{
  kind: "Director/Docker"
  metadata : {
    name : <instance_guid>,
    labels : {
      state : <success/deleted etc>
    }
  },
  spec: {
    <options>
  },
  status: {
    response: <response>,
    lastOperation: <lo>,
    state: <success/deleted etc>
  }
}

Example:

{
  "kind": "Director",
  "apiVersion": "deployment.servicefabrik.io/v1alpha1",
  "metadata": {
    "name": "55ac1af2-abcd-4541-ae78-abcdefgh8d94",
    "namespace": "default",
    "selfLink": "/apis/deployment.servicefabrik.io/v1alpha1/namespaces/default/directors/55ac1af2-abcd-4541-ae78-abcdefgh8d94",
    "uid": "eda66a0b-abcd-11e8-b417-abcdefgh13dc",
    "resourceVersion": "60603",
    "generation": 1,
    "creationTimestamp": "2018-07-25T11:29:01Z",
    "labels": {
      "instance_guid": "55ac1af2-abcd-4541-ae78-abcdefgh8d94",
      "last_backup_defaultbackups": "ffde9529-cefd-45db-abcd-abcdefghd4d8",
      "state": "in_queue"
    }
  },
  "spec": {
    "options": "{}"
  },
  "status": {
    "state": "in_queue",
    "lastOperation": "created",
    "response": "{}"
  }
}

Backup:

Schema

{
  kind: "DefaultBackup"
  metadata : {
    name : <backup_guid>,
    labels : {
      instance_guid : <instance for which backup was taken>,
      state : <current state of operation>
    }
  },
  spec: {
    options: "string"
  },
  status: {
    state: "string" 
    error: "string"
    lastOperation: "string"
    response: "string"
  }
}

Example:

{
  "kind": "DefaultBackup",
  "apiVersion": "backup.servicefabrik.io/v1alpha1",
  "metadata": {
    "name": "ffde9529-cefd-45db-abcd-abcdefghd4d8",
    "namespace": "default",
    "selfLink": "/apis/backup.servicefabrik.io/v1alpha1/namespaces/default/defaultbackups/ffde9529-cefd-45db-8c2a-6f5f0f71d4d8",
    "uid": "fa5d5192-94f7-11e8-8e4f-abcdefghde69e",
    "resourceVersion": "49444",
    "generation": 3,
    "creationTimestamp": "2018-07-31T19:29:01Z",
    "labels": {
      "instance_guid": "55ac1af2-abcd-4541-ae78-abcdefgh8d94",
      "state": "succeeded"
    },
    "annotations": {
      "lockedByManager": "10.0.2.2"
    }
  },
  "spec": {
    "options": "{\"guid\":\"ffde9529-cefd-45db-abcd-abcdefghd4d8\",\"instance_guid\":\"55ac1af2-abcd-4541-ae78-abcdefgh8d94\",\"plan_id\":\"bc158c9a-7934-401e-94ab-057082a5073f\",\"service_id\":\"24731fb8-7b84-4f57-914f-c3d55d793dd4\"}"
  },
  "status": {
    "state": "succeeded",
    "lastOperation": "created",
    "response": "{\"service_id\":\"24731fb8-7b84-4f57-914f-c3d55d793dd4\",\"plan_id\":\"bc158c9a-7934-401e-94ab-057082a5073f\",\"instance_guid\":\"55ac1af2-abcd-4541-ae78-abcdefgh8d94\"}"
  }
}

Lock:

Schema

{
  kind: "Lock"
  metadata : {
    name : <lock name>,
  },
  spec: {
    options: {
      JSON.stringify({
        lockType: <Read/Write>,
        lockTime: <time in UTC when lock was acquired, can be updated when one wants to refresh lock>,
        lockTTL: <lock ttl=> set to Infinity if not provided>,
        lockedResourceDetails: <details of locked resource like resourceType(backup/director), resourceId, operation etc>
      })    
    }
  }
}

Example:

   {
  "kind": "DeploymentLock",
  "apiVersion": "lock.servicefabrik.io/v1alpha1",
  "metadata": {
    "name": "55ac1af2-abcd-4541-ae78-abcdefgh8d94",
    "namespace": "default",
    "selfLink": "/apis/lock.servicefabrik.io/v1alpha1/namespaces/default/deploymentlocks/dc88713e-9c52-4e8a-822d-b5c16832991a",
    "uid": "9857eec2-93d8-abcd-ae73-abcdefghe69e",
    "resourceVersion": "39318",
    "generation": 1,
    "creationTimestamp": "2018-07-30T09:11:51Z"
  },
  "spec": {
    "options": "{\"lockedResourceDetails\":{\"resourceGroup\":\"backup\",\"resourceType\":\"defaultbackups\",\"resourceId\":\"fde9529-cefd-45db-abcd-abcdefghd4d8\",\"operation\":\"backup\"},\"lockType\":\"READ\",\"lockTTL\":null,\"lockTime\":\"2018-07-30T09:11:51.283Z\"}"
  },
  "status": {}
}

Bind:

{
  kind: "DirectorBind/DockerBind"
  metadata : {
    name : <bind_id>,
    labels : {
      instance_guid : <instance for which backup was taken>,
      state : <current state of operation>
    }
  },
  spec: {
    instance: <instance_guid>,
    options: "string"
  },
  status: {
    state: "string"
    response: "string"
  }
}

High level execution flow

Lifecycle Operations:

create:

  • ApiController creates a deployment(director/docker) resource with state as in_queue

  • BoshManager is watching on director resource and gets an in_queue event

  • Starts provisioning and changes state to in_progress

update:

  • ApiController updates the deployment(director/docker) resource with state as update

  • BoshManager is watching on director resource and gets an update event

Starts updating and changes state to in_progress

delete:

  • ApiController updates the deployment(director/docker) resource with state as delete

  • BoshManager is watching on director resource and gets an delete event

  • Starts deletion and changes state to in_progress

lastOperation:

  • Gets state of resource from Apiserver

  • In case of delete controller deletes the resource

bind:

  • ApiController creates a bind(directorbind/dockerbind) resource with state as in_queue and waits for state to change to succeeded

  • BindManager is watching on bind resource and gets an in_queue event

  • Starts bind and changes state to succeeded

unbind:

  • ApiController updates the bind(directorbind/dockerbind) resource with state as delete and waits for state to change to succeeded and then delete bind resource

  • BindManager is watching on bind resource and gets an delete event

  • Unbinds and changes state to succeeded

Backup Operation:

startBackup:

  • ApiController creates a backup(defaultbackup) resource with state as in_queue

  • BackupManager is watching on backup resource and gets an in_queue event

  • Starts backup and changes state to in_progress

abortBackup:

  • ApiController updates the backup(defaultbackup) resource with state as abort and waits for state to change into aborting

  • BackupManager is watching on backup resource and gets an abort event

  • Starts abort and changes state to aborting

deletebackup:

  • ApiController updates the backup(defaultbackup) resource with state as delete and waits for state to change into deleted

  • BackupManager is watching on backup resource and gets an delete event

  • Deletes and changes state to deleted