You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by tl...@apache.org on 2020/08/04 20:23:35 UTC

[incubator-sdap-ingester] branch SDAP-267 updated (c7d2145 -> e309727)

This is an automated email from the ASF dual-hosted git repository.

tloubrieu pushed a change to branch SDAP-267
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-ingester.git.


 discard c7d2145  organize logs in operator
 discard 628f181  add a on.update kopf event for crd updates
     new e309727  add a on.update kopf event for crd updates

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (c7d2145)
            \
             N -- N -- N   refs/heads/SDAP-267 (e309727)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[incubator-sdap-ingester] 01/01: add a on.update kopf event for crd updates

Posted by tl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tloubrieu pushed a commit to branch SDAP-267
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-ingester.git

commit e309727b8536b21538a882c18191275142553dea
Author: thomas loubrieu <th...@jpl.nasa.gov>
AuthorDate: Tue Aug 4 13:17:47 2020 -0700

    add a on.update kopf event for crd updates
    
    organize logs in operator
---
 config_operator/README.md                          | 10 +++++-
 .../config_source/RemoteGitConfig.py               |  4 +--
 config_operator/config_operator/main.py            | 38 +++++++++++++++++-----
 .../containers/k8s/config-operator-crd.yml         |  2 +-
 .../containers/k8s/deployment-git-src.yml          | 23 -------------
 config_operator/containers/k8s/git-repo-test.yml   |  4 +--
 6 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/config_operator/README.md b/config_operator/README.md
index ba4c6fc..5f02804 100644
--- a/config_operator/README.md
+++ b/config_operator/README.md
@@ -28,7 +28,11 @@ To publish the docker image on dockerhub do (step necessary for kubernetes deplo
     docker push nexusjpl/config-operator:latest
     
 ## Kubernetes
-    
+
+Delete pre-existing operator definitions:
+
+    kubectl delete deployment.apps/git-repo-config-operator  -n sdap
+   
 Deploy the gitbasedconfig operator:
 
      kubectl apply -f containers/k8s/config-operator-crd.yml -n sdap
@@ -45,6 +49,10 @@ Check that the configMap has been generated:
 
     kubectl get configmaps -n sdap
     
+Test an update of the config operator configuration:
+
+    kubectl set image gitbasedconfig/nginx-deployment nginx=nginx:1.16.1 --record
+    
 
     
     
\ No newline at end of file
diff --git a/config_operator/config_operator/config_source/RemoteGitConfig.py b/config_operator/config_operator/config_source/RemoteGitConfig.py
index 38cbe2d..350fcfc 100644
--- a/config_operator/config_operator/config_source/RemoteGitConfig.py
+++ b/config_operator/config_operator/config_source/RemoteGitConfig.py
@@ -39,8 +39,8 @@ class RemoteGitConfig(LocalDirConfig):
         self._git_token = git_token
         if local_dir is None:
             local_dir = DEFAULT_LOCAL_REPO_DIR
-        self._update_every_seconds = update_every_seconds
-        super().__init__(local_dir, update_every_seconds=self._update_every_seconds)
+        super().__init__(local_dir, update_every_seconds=update_every_seconds)
+
 
         if repo:
             self._repo = repo
diff --git a/config_operator/config_operator/main.py b/config_operator/config_operator/main.py
index fac6741..45d530f 100644
--- a/config_operator/config_operator/main.py
+++ b/config_operator/config_operator/main.py
@@ -8,11 +8,7 @@ logging.basicConfig(level=logging.INFO)
 logger = logging.getLogger(__name__)
 
 
-@kopf.on.create('sdap.apache.org', 'v1', 'gitbasedconfigs')
-def create_fn(body, spec, **kwargs):
-    # Get info from Git Repo Config object
-    namespace = body['metadata']['namespace']
-
+def create_config_synchronizer(spec, namespace):
     if 'git-url' not in spec.keys():
         raise kopf.HandlerFatalError(f"git-url must be set.")
     if 'config-map' not in spec.keys():
@@ -23,22 +19,48 @@ def create_fn(body, spec, **kwargs):
     config_map = spec['config-map']
     logger.info(f'config-map = {config_map}')
 
-    _kargs = {}
+    _kwargs = {}
     for k in {'git-branch', 'git-username', 'git-token', 'update-every-seconds'}:
         if k in spec:
             logger.info(f'{k} = {spec[k]}')
-            _kargs[k.replace('-', '_')] = spec[k]
+            _kwargs[k.replace('-', '_')] = spec[k]
 
-    config = RemoteGitConfig(git_url, **_kargs)
+    config = RemoteGitConfig(git_url, **_kwargs)
 
     config_map = K8sConfigMap(config_map, namespace, config)
 
     asyncio.run(config.when_updated(config_map.publish))
 
     msg = f"configmap {config_map} created from git repo {git_url}"
+
+    return msg
+
+
+@kopf.on.create('sdap.apache.org', 'v1', 'gitbasedconfigs')
+def create_fn(body, spec, **kwargs):
+    logger.info(f'sdap config operator creation')
+
+    namespace = body['metadata']['namespace']
+
+    msg = create_config_synchronizer(spec, namespace)
+
+    logger.info(f'sdap config operator created {msg}')
+
+    return {'message': msg}
+
+
+@kopf.on.update('sdap.apache.org', 'v1', 'gitbasedconfigs')
+def update_fn(spec, status, namespace, **kwargs):
+    logger.info(f'sdap config operator update')
+
+    msg = create_config_synchronizer(spec, namespace)
+
+    logger.info(f'sdap config operator updated {msg}')
+
     return {'message': msg}
 
 
+
 @kopf.on.login()
 def login_fn(**kwargs):
     return kopf.login_via_client(**kwargs)
diff --git a/config_operator/containers/k8s/config-operator-crd.yml b/config_operator/containers/k8s/config-operator-crd.yml
index 9f6d2ad..2159c00 100644
--- a/config_operator/containers/k8s/config-operator-crd.yml
+++ b/config_operator/containers/k8s/config-operator-crd.yml
@@ -12,7 +12,7 @@ spec:
   names:
     plural: gitbasedconfigs
     singular: gitbasedconfig
-    kind: gitBasedConfig
+    kind: GitBasedConfig
     shortNames:
     - gitcfg
   validation:
diff --git a/config_operator/containers/k8s/deployment-git-src.yml b/config_operator/containers/k8s/deployment-git-src.yml
deleted file mode 100644
index 99b268d..0000000
--- a/config_operator/containers/k8s/deployment-git-src.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: config-operator
-  labels:
-    app: sdap-config-operator
-spec:
-  replicas: 1
-  selector:
-    matchLabels:
-      app: sdap-config-operator
-  template:
-    metadata:
-      labels:
-        app: sdap-config-operator
-    spec:
-      containers:
-      - name: sdap-config-operator
-        image: tloubrieu/config-operator:latest
-        imagePullPolicy: IfNotPresent
-        command: ['config-operator', '--git-url', 'https://github.com/tloubrieu-jpl/sdap-ingester-config' , '--namespace', 'sdap', '--config-map', 'collection-ingester-conf', '-u']
-
-
diff --git a/config_operator/containers/k8s/git-repo-test.yml b/config_operator/containers/k8s/git-repo-test.yml
index 6a98454..79ad518 100644
--- a/config_operator/containers/k8s/git-repo-test.yml
+++ b/config_operator/containers/k8s/git-repo-test.yml
@@ -1,9 +1,9 @@
 apiVersion: sdap.apache.org/v1
-kind: gitBasedConfig
+kind: GitBasedConfig
 metadata:
   name: collections-config-gitcfg
 spec:
   git-url: https://github.com/tloubrieu-jpl/sdap-ingester-config.git
-  git-branch: master
+  git-branch: bigdata
   git-token: whatever
   config-map: my-configmap
\ No newline at end of file