Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local gctl: auto set namespace selector against watch #102

Open
AmitKumarDas opened this issue Mar 6, 2020 · 2 comments
Open

local gctl: auto set namespace selector against watch #102

AmitKumarDas opened this issue Mar 6, 2020 · 2 comments
Labels
config gctl Generic Controller help wanted Extra attention is needed library Use Metac as a library

Comments

@AmitKumarDas
Copy link
Owner

Problem Statement: I would like to use Metac as a library that is packaged as my own binary. This binary will get deployed as a Kubernetes Deployment or STS. I would like to use MetaController CR as a config that should only consider watches in this Deployment/STS namespace.

@AmitKumarDas AmitKumarDas changed the title local gctl: auto set namespace selector against watch via some environment variable local gctl: auto set namespace selector against watch Mar 6, 2020
@AmitKumarDas AmitKumarDas added config gctl Generic Controller library Use Metac as a library help wanted Extra attention is needed labels Mar 6, 2020
@grzesuav
Copy link
Collaborator

@AmitKumarDas maybe could you elaborate what is needed to achieve this behavior ?

@AmitKumarDas
Copy link
Owner Author

AmitKumarDas commented Mar 11, 2020

I will try to explain via a sample config for GenericController.

NOTE: Metac config is a yaml file with schema that adheres to one or more GenericController(s). This config is typically placed at /etc/config/metac/ path of the container. This container hosts metac binary that reads this config & in turn starts the informers (one informer per watch mentioned in GenericController). This mode of running metac is also known as local mode.

NOTE: Refer https://github.com/AmitKumarDas/metac/blob/master/start/start.go to learn on this mode of running metac

NOTE: In my use-case this binary is a golang project that uses metac as a library

Following is a sample config that makes use of 2 GenericControllers. On the whole, we want the metac binary to start informers for watches with kind CStorClusterPlan & CStorClusterStorageSet

apiVersion: metac.openebs.io/v1alpha1
kind: GenericController
metadata:
  name: sync-plan
  namespace: cspauto
spec:
  # I want to watch kind CStorClusterPlan that are created under namespace
  # that matches the namespace of metac binary (that has this config file)
  watch:
    apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterplans
  attachments:
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterstoragesets
    updateStrategy:
      method: InPlace
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterconfigs
  hooks:
    sync:
      inline:
        funcName: sync/cstorclusterplan
---
apiVersion: metac.openebs.io/v1alpha1
kind: GenericController
metadata:
  name: sync-storageset
  namespace: cspauto
spec:
  # I want to watch kind CStorClusterStorageSet that are created under namespace
  # that matches the namespace of metac binary (that has this config file)
  watch:
    apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterstoragesets
  attachments:
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: storages
    updateStrategy:
      method: InPlace
  hooks:
    sync:
      inline:
        funcName: sync/cstorclusterstorageset

Coming back to the problem statement, I would like to spin up multiple metac binaries in dedicated namespaces. I want each binary to lookup up the watches that belong to its own namespace & proceed with its reconciliation.

Possible solution:

We can define following new environment variables e.g.:

  • MATCH_WATCH_WITH_SELF_NAMESPACE: <true/false>
  • SELF_NAMESPACE: (this will be a K8s downward API that will hold the POD's namespace)

Now when metac starts, the resulting GenericControllers will be like following:

apiVersion: metac.openebs.io/v1alpha1
kind: GenericController
metadata:
  name: sync-plan
  namespace: cspauto
spec:
  watch:
    apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterplans
    advancedSelector:
      selectorTerms:
      - matchFields:
          metadata.namespace: <POD's namesapce>
  attachments:
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterstoragesets
    updateStrategy:
      method: InPlace
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterconfigs
  hooks:
    sync:
      inline:
        funcName: sync/cstorclusterplan
---
apiVersion: metac.openebs.io/v1alpha1
kind: GenericController
metadata:
  name: sync-storageset
  namespace: cspauto
spec:
  watch:
    apiVersion: dao.mayadata.io/v1alpha1
    resource: cstorclusterstoragesets
    advancedSelector:
      selectorTerms:
      - matchFields:
          metadata.namespace: <POD's namesapce>
  attachments:
  - apiVersion: dao.mayadata.io/v1alpha1
    resource: storages
    updateStrategy:
      method: InPlace
  hooks:
    sync:
      inline:
        funcName: sync/cstorclusterstorageset

Above is applicable when metac binary runs by looking up its config file (described above). In other words metac was started with following args:

 args:
        - --run-as-local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config gctl Generic Controller help wanted Extra attention is needed library Use Metac as a library
Projects
None yet
Development

No branches or pull requests

2 participants