Added seed code for caas-helm. 97/597/2
authorSzekeres, Balazs (Nokia - HU/Budapest) <balazs.szekeres@nokia.com>
Thu, 2 May 2019 11:33:57 +0000 (13:33 +0200)
committerSzekeres, Balazs (Nokia - HU/Budapest) <balazs.szekeres@nokia.com>
Mon, 6 May 2019 07:12:49 +0000 (09:12 +0200)
Added seed code for caas-helm.

Change-Id: Id241961056a414ad76f98ca79e4591590ee44c71
Signed-off-by: Szekeres, Balazs (Nokia - HU/Budapest) <balazs.szekeres@nokia.com>
34 files changed:
LICENSE [new file with mode: 0644]
SPECS/caas-chartrepo.spec [new file with mode: 0644]
SPECS/caas-helm.spec [new file with mode: 0644]
ansible/playbooks/chart_repo.yaml [new file with mode: 0644]
ansible/playbooks/helm.yaml [new file with mode: 0644]
ansible/roles/chart_repo/meta/main.yml [new file with mode: 0644]
ansible/roles/chart_repo/tasks/main.yaml [new file with mode: 0644]
ansible/roles/chart_repo/templates/chart-repo.yml [new file with mode: 0644]
ansible/roles/chart_repo/templates/chart-repo_service.yml [new file with mode: 0644]
ansible/roles/helm/meta/main.yaml [new file with mode: 0644]
ansible/roles/helm/tasks/config.yml [new file with mode: 0644]
ansible/roles/helm/tasks/main.yml [new file with mode: 0644]
ansible/roles/helm/templates/tiller-service.yml [new file with mode: 0644]
ansible/roles/helm/templates/tiller.yml [new file with mode: 0644]
docker-build/chartrepohandler/Dockerfile [new file with mode: 0644]
docker-build/chartrepohandler/bom.json [new file with mode: 0644]
docker-build/chartrepohandler/mainstart.sh [new file with mode: 0644]
docker-build/helm-builder/Dockerfile [new file with mode: 0644]
docker-build/tiller/Dockerfile [new file with mode: 0644]
docker-build/tiller/bom.json [new file with mode: 0644]
docker-build/tiller/mainstart.sh [new file with mode: 0755]
src/chart-repo-handler/.gitignore [new file with mode: 0644]
src/chart-repo-handler/README.md [new file with mode: 0644]
src/chart-repo-handler/build.sh [new file with mode: 0644]
src/chart-repo-handler/env.sh [new file with mode: 0644]
src/chart-repo-handler/glide.lock [new file with mode: 0644]
src/chart-repo-handler/glide.yaml [new file with mode: 0644]
src/chart-repo-handler/main.go [new file with mode: 0644]
src/chart-repo-handler/pkg/api/handlers.go [new file with mode: 0644]
src/chart-repo-handler/pkg/api/logger.go [new file with mode: 0644]
src/chart-repo-handler/pkg/api/routers.go [new file with mode: 0644]
src/chart-repo-handler/pkg/chartutil/load.go [new file with mode: 0644]
src/chart-repo-handler/pkg/config/config.go [new file with mode: 0644]
src/chart-repo-handler/pkg/repo/index.go [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..f433b1a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
diff --git a/SPECS/caas-chartrepo.spec b/SPECS/caas-chartrepo.spec
new file mode 100644 (file)
index 0000000..57556a7
--- /dev/null
@@ -0,0 +1,86 @@
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+%define COMPONENT chartrepo
+%define RPM_NAME caas-%{COMPONENT}
+%define RPM_MAJOR_VERSION 1.0.0
+%define RPM_MINOR_VERSION 1
+%define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
+%define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
+%define docker_save_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save
+
+Name:           %{RPM_NAME}
+Version:        %{RPM_MAJOR_VERSION}
+Release:        %{RPM_MINOR_VERSION}%{?dist}
+Summary:        Containers as a Service %{COMPONENT} component
+License:        %{_platform_licence} and MIT license and BSD and Apache License and Lesser General Public License
+BuildArch:      x86_64
+Vendor:         %{_platform_vendor} and kubernetes/kubernetes unmodified
+Source0:        %{name}-%{version}.tar.gz
+
+Requires: docker-ce >= 18.09.2
+BuildRequires: docker-ce-cli >= 18.09.2
+
+%description
+This rpm contains the %{COMPONENT} container for CaaS subsystem.
+This container contains the %{COMPONENT} service.
+
+%prep
+%autosetup
+
+%build
+rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/src/*   %{docker_build_dir}/chartrepohandler/
+docker build \
+  --network=host \
+  --no-cache \
+  --force-rm \
+  --build-arg HTTP_PROXY="${http_proxy}" \
+  --build-arg HTTPS_PROXY="${https_proxy}" \
+  --build-arg NO_PROXY="${no_proxy}" \
+  --build-arg http_proxy="${http_proxy}" \
+  --build-arg https_proxy="${https_proxy}" \
+  --build-arg no_proxy="${no_proxy}" \
+  --tag %{COMPONENT}:%{IMAGE_TAG} \
+  %{docker_build_dir}/chartrepohandler
+mkdir -p %{docker_save_dir}
+docker save %{COMPONENT}:%{IMAGE_TAG} | gzip -c > %{docker_save_dir}/%{COMPONENT}:%{IMAGE_TAG}.tar
+docker rmi %{COMPONENT}:%{IMAGE_TAG}
+
+%install
+mkdir -p %{buildroot}/%{_caas_container_tar_path}
+rsync -av %{docker_save_dir}/* %{buildroot}/%{_caas_container_tar_path}/
+
+mkdir -p %{buildroot}/%{_roles_path}
+rsync -av ansible/roles/chart_repo %{buildroot}/%{_roles_path}/
+
+install -D ansible/playbooks/chart_repo.yaml %{buildroot}/%{_playbooks_path}/chart_repo.yaml
+
+%files
+%{_caas_container_tar_path}/*.tar
+%{_roles_path}/chart_repo/
+%{_playbooks_path}/chart_repo.yaml
+
+%preun
+
+%post
+mkdir -p %{_postconfig_path}
+ln -s %{_playbooks_path}/chart_repo.yaml          %{_postconfig_path}/
+
+%postun
+if [ $1 -eq 0 ]; then
+  rm -f %{_playbooks_path}/chart_repo.yaml
+fi
+
+%clean
+rm -rf ${buildroot}
diff --git a/SPECS/caas-helm.spec b/SPECS/caas-helm.spec
new file mode 100644 (file)
index 0000000..87d69d3
--- /dev/null
@@ -0,0 +1,118 @@
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+%define COMPONENT helm
+%define RPM_NAME caas-%{COMPONENT}
+%define RPM_MAJOR_VERSION 2.13.1
+%define RPM_MINOR_VERSION 1
+%define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION}
+%define go_version 1.11.5
+%define cni_plugins_version 0.7.0
+%define binary_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/binary-save
+%define docker_build_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build
+%define docker_save_dir %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save
+%define built_binaries_dir /binary-save
+
+Name:           %{RPM_NAME}
+Version:        %{RPM_MAJOR_VERSION}
+Release:        %{RPM_MINOR_VERSION}%{?dist}
+Summary:        Containers as a Service %{COMPONENT} component
+License:        %{_platform_licence} and MIT license and BSD and Apache License and Lesser General Public License
+BuildArch:      x86_64
+Vendor:         %{_platform_vendor} and helm/helm unmodified
+Source0:        %{name}-%{version}.tar.gz
+
+Requires: docker-ce >= 18.09.2
+BuildRequires: docker-ce-cli >= 18.09.2
+
+%description
+This rpm contains the %{COMPONENT} container for CaaS subsystem.
+This container contains the %{COMPONENT} service.
+
+%prep
+%autosetup
+
+%build
+# Build Helm binaries
+docker build \
+  --network=host \
+  --no-cache \
+  --force-rm \
+  --build-arg HTTP_PROXY="${http_proxy}" \
+  --build-arg HTTPS_PROXY="${https_proxy}" \
+  --build-arg NO_PROXY="${no_proxy}" \
+  --build-arg http_proxy="${http_proxy}" \
+  --build-arg https_proxy="${https_proxy}" \
+  --build-arg no_proxy="${no_proxy}" \
+  --build-arg HELM_VERSION="%{version}" \
+  --build-arg go_version="%{go_version}" \
+  --build-arg binaries="%{built_binaries_dir}" \
+  --tag helm-builder:%{IMAGE_TAG} \
+  %{docker_build_dir}/helm-builder
+
+mkdir -p %{binary_build_dir}
+builder_container=$(docker run -id --rm --network=none --entrypoint=/bin/sh helm-builder:%{IMAGE_TAG})
+docker cp ${builder_container}:%{built_binaries_dir}/helm   %{binary_build_dir}/
+docker cp ${builder_container}:%{built_binaries_dir}/tiller %{binary_build_dir}/
+docker rm -f ${builder_container}
+docker rmi helm-builder:%{IMAGE_TAG}
+
+# Build tiller container image
+rsync -av %{binary_build_dir}/* %{docker_build_dir}/tiller/
+docker build \
+  --network=host \
+  --no-cache \
+  --force-rm \
+  --build-arg HTTP_PROXY="${http_proxy}" \
+  --build-arg HTTPS_PROXY="${https_proxy}" \
+  --build-arg NO_PROXY="${no_proxy}" \
+  --build-arg http_proxy="${http_proxy}" \
+  --build-arg https_proxy="${https_proxy}" \
+  --build-arg no_proxy="${no_proxy}" \
+  --tag tiller:%{IMAGE_TAG} \
+  %{docker_build_dir}/tiller
+mkdir -p %{docker_save_dir}/
+docker save tiller:%{IMAGE_TAG} | gzip -c > "%{docker_save_dir}/tiller:%{IMAGE_TAG}.tar"
+docker rmi tiller:%{IMAGE_TAG}
+
+%install
+mkdir -p %{buildroot}/%{_caas_container_tar_path}
+rsync -av %{docker_save_dir}/* %{buildroot}/%{_caas_container_tar_path}/
+
+mkdir -p %{buildroot}/%{_roles_path}
+rsync -av ansible/roles/helm %{buildroot}/%{_roles_path}/
+
+install -D ansible/playbooks/helm.yaml %{buildroot}/%{_playbooks_path}/helm.yaml
+
+install -D -m 0755 %{binary_build_dir}/helm %{buildroot}/usr/bin/helm
+
+%files
+%{_caas_container_tar_path}/tiller:%{IMAGE_TAG}.tar
+%{_roles_path}/helm
+%{_playbooks_path}/helm.yaml
+/usr/bin/helm
+
+%preun
+
+%post
+mkdir -p %{_postconfig_path}
+ln -s %{_playbooks_path}/helm.yaml %{_postconfig_path}/
+
+%postun
+if [ $1 -eq 0 ]; then
+  rm -f %{_postconfig_path}/helm.yaml
+fi
+
+%clean
+rm -rf ${buildroot}
diff --git a/ansible/playbooks/chart_repo.yaml b/ansible/playbooks/chart_repo.yaml
new file mode 100644 (file)
index 0000000..f3deaa0
--- /dev/null
@@ -0,0 +1,22 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# cmframework.requires: image_push.yaml
+- hosts: installation_controller:&caas_master
+  strategy: free
+  become: true
+  become_user: "{{ users.admin_user_name }}"
+  roles:
+    - chart_repo
diff --git a/ansible/playbooks/helm.yaml b/ansible/playbooks/helm.yaml
new file mode 100644 (file)
index 0000000..df35d52
--- /dev/null
@@ -0,0 +1,23 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# cmframework.requires: chart_repo.yaml
+- hosts: caas_master
+  strategy: linear
+  become: true
+  become_user: "{{ users.admin_user_name }}"
+  roles:
+    - role: helm
+
diff --git a/ansible/roles/chart_repo/meta/main.yml b/ansible/roles/chart_repo/meta/main.yml
new file mode 100644 (file)
index 0000000..37aa254
--- /dev/null
@@ -0,0 +1,53 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+dependencies:
+  - role: creategroup
+    _name: chartrepo
+    _gid: "{{ caas.uid.chartrepo }}"
+    become: true
+    become_user: "root"
+
+  - role: createuser
+    _name: chartrepo
+    _group: chartrepo
+    _groups: ''
+    _shell: /sbin/nologin
+    _home: /
+    _uid: "{{ caas.uid.chartrepo }}"
+    become: true
+    become_user: "root"
+
+  - role: cert
+    instance: "chart-repo{{ nodeindex }}"
+    cert_path: /etc/chart-repo/ssl
+    add_users:
+      - chartrepo
+    alt_names:
+      dns:
+        - "{{ caas.chart_repo_url }}"
+    become: true
+    become_user: "root"
+
+  - role: docker_image_load
+    images:
+      - chartrepo
+
+  - role: docker_image_push
+    images:
+      - chartrepo
+    when: nodename | search("caas_master1")
+
+  - role: manifests
diff --git a/ansible/roles/chart_repo/tasks/main.yaml b/ansible/roles/chart_repo/tasks/main.yaml
new file mode 100644 (file)
index 0000000..a5a885b
--- /dev/null
@@ -0,0 +1,56 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: The swift user is
+  shell: grep "export SWIFT_USER=" /etc/swift/usr/admin/env_file | awk -F"=" '{print($2) }'
+  register: swift_user
+
+- name: The swift tenant is
+  shell: grep "export SWIFT_TENANT=" /etc/swift/usr/admin/env_file | awk -F"=" '{print($2) }'
+  register: swift_tenant
+
+- name: The swift pass is
+  shell: grep "export SWIFT_PASS=" /etc/swift/usr/admin/env_file | awk -F"=" '{print($2) }'
+  register: swift_pass
+
+- name: Chart repo handler template
+  template:
+    src: "chart-repo.yml"
+    dest: "{{ caas.manifests_directory }}/chart-repo.yml"
+
+- name: Chart repo service template
+  template:
+    src: "chart-repo_service.yml"
+    dest: "{{ caas.manifests_directory }}/chart-repo_service.yml"
+
+- name: Authenticate into swift
+  shell: 'curl -XGET -i -H"X-Auth-User:{{ swift_tenant.stdout }}:{{ swift_user.stdout }}" -H"X-Auth-Key:{{ swift_pass.stdout }}" {{ caas.swift }}/auth/v1.0 | grep X-Auth-Token: | awk "{ print \$2 }"'
+  register: SWIFT_AUTH_KEY
+
+- name: Create packages folder/container into swift
+  shell: 'curl -XPUT -H"X-Auth-Token: {{ SWIFT_AUTH_KEY.stdout }}" {{ caas.swift }}/v1.0/AUTH_admin/packages'
+
+- name: Read the swift main folder/container and check if is there the packages folder/conatiner
+  shell: 'curl -XGET -H"X-Auth-Token: {{ SWIFT_AUTH_KEY.stdout }}" {{ caas.swift }}/v1.0/AUTH_admin | grep packages'
+
+- name: start chart repo handler
+  kubectl:
+    manifest: "{{ caas.manifests_directory }}/chart-repo.yml"
+    state: present
+
+- name: start chart repo service
+  kubectl:
+    manifest: "{{ caas.manifests_directory }}/chart-repo_service.yml"
+    state: present
diff --git a/ansible/roles/chart_repo/templates/chart-repo.yml b/ansible/roles/chart_repo/templates/chart-repo.yml
new file mode 100644 (file)
index 0000000..af4f5e8
--- /dev/null
@@ -0,0 +1,94 @@
+{#
+Copyright 2019 Nokia
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+---
+apiVersion: apps/v1beta2
+kind: Deployment
+metadata:
+  name: chart-repo
+  namespace: kube-system
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      {{ caas.kubernetes_component_label }}: chart-repo
+  template:
+    metadata:
+      annotations:
+        danm.k8s.io/interfaces: |
+          [
+            {
+              "network":"flannel"
+            }
+          ]
+      labels:
+        {{ caas.kubernetes_component_label }}: chart-repo
+    spec:
+      dnsPolicy: ClusterFirst
+      nodeSelector:
+        nodename: caas_master1
+      securityContext:
+        runAsUser: {{ caas.uid.chartrepo }}
+      containers:
+        - name: chart-repo-handler
+          image: {{ container_image_names | select('search', '/chartrepo') | list | last }}
+          imagePullPolicy: IfNotPresent
+          ## Limits equals requets to put the container into qualified QoS category
+          resources:
+            limits:
+              cpu: "0.2"
+              memory: "128Mi"
+            requests:
+              cpu: "0.2"
+              memory: "128Mi"
+          command:
+            - "/usr/bin/mainstart.sh"
+          env:
+            - name: CHARTREPOHANDLER_AUTHURL
+              value: {{ caas.swift }}/auth/v1.0
+            - name: CHARTREPOHANDLER_AUTHUSER
+              value: admin:admin
+            - name: CHARTREPOHANDLER_LISTENONPORT
+              value: "{{ caas.chart_repo_port }}"
+            - name: CHARTREPOHANDLER_LISTENONINTERFACE
+              value: "{{ caas.internal_flannel_interface }}"
+            - name: CHARTREPOHANDLER_AUTHKEY
+              value: "{{ swift_pass.stdout }}"
+            - name: CHARTREPOHANDLER_CONTAINER
+              value: packages
+            - name: CHARTREPOHANDLER_REPOURL
+              value: https://{{ caas.chart_repo_url }}
+            - name: CHARTREPOHANDLER_INDEXPATH
+              value: charts
+            - name: CHARTREPOHANDLER_TLSCERTPATH
+              value: /etc/chart-repo/ssl/chart-repo{{ nodeindex }}.pem
+            - name: CHARTREPOHANDLER_TLSKEYPATH
+              value: /etc/chart-repo/ssl/chart-repo{{ nodeindex }}-key.pem
+            - name: CHARTREPOHANDLER_TLSCAPATH
+              value: /etc/chart-repo/ssl/ca.pem
+          volumeMounts:
+            - name: time-mount
+              mountPath: /etc/localtime
+              readOnly: true
+            - name: chart-repo-cert
+              mountPath: /etc/chart-repo/ssl
+              readOnly: true
+      volumes:
+        - name: time-mount
+          hostPath:
+            path: /etc/localtime
+        - name: chart-repo-cert
+          hostPath:
+            path: /etc/chart-repo/ssl
diff --git a/ansible/roles/chart_repo/templates/chart-repo_service.yml b/ansible/roles/chart_repo/templates/chart-repo_service.yml
new file mode 100644 (file)
index 0000000..d4fba23
--- /dev/null
@@ -0,0 +1,31 @@
+{#
+Copyright 2019 Nokia
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    {{ caas.kubernetes_component_label }}: chart-repo
+  name: chart-repo
+  namespace: kube-system
+spec:
+  clusterIP: {{ caas.chart_repo_ip }}
+  ports:
+    - name: chart-repo
+      port: {{ caas.chart_repo_port }}
+      targetPort: {{ caas.chart_repo_port }}
+  selector:
+   {{ caas.kubernetes_component_label }}: chart-repo
diff --git a/ansible/roles/helm/meta/main.yaml b/ansible/roles/helm/meta/main.yaml
new file mode 100644 (file)
index 0000000..96fd409
--- /dev/null
@@ -0,0 +1,26 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+dependencies:
+  - role: docker_image_load
+    images:
+      - tiller
+
+  - role: docker_image_push
+    images:
+      - tiller
+    when: nodename | search("caas_master1")
+
+  - role: manifests
diff --git a/ansible/roles/helm/tasks/config.yml b/ansible/roles/helm/tasks/config.yml
new file mode 100644 (file)
index 0000000..7b81a6b
--- /dev/null
@@ -0,0 +1,69 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: create the necessary directories
+  file:
+    path: "{{ item }}"
+    state: directory
+  with_items:
+    - "{{ caas.helm_home }}/repository"
+    - "{{ caas.helm_home }}/repository/local"
+
+- name: allowing cloud_admin_user to access helm_home folder recursively
+  acl:
+    path:  "{{ caas.helm_home }}"
+    entity: "{{ users.admin_user_name }}"
+    etype: user
+    permissions: rwx
+    state: present
+    recursive: yes
+    default: yes
+  become_user: "root"
+
+- name: applies the effective rights mask to the helm_home folder recursively
+  acl:
+    path:  "{{ caas.helm_home }}"
+    etype: mask
+    permissions: rwx
+    state: present
+    recursive: yes
+    default: yes
+  become_user: "root"
+
+- name: touch the repository file
+  copy:
+    content: ""
+    owner: "{{ users.admin_user_name }}"
+    group: "{{ users.admin_user_name }}"
+    dest: "{{ caas.helm_home }}/repository/repositories.yaml"
+
+- name: create the local repository file
+  copy:
+    content: |
+      apiVersion: v1
+      entries: {}
+    owner: "{{ users.admin_user_name }}"
+    group: "{{ users.admin_user_name }}"
+    dest: "{{ caas.helm_home }}/repository/local/index.yaml"
+
+- name: init helm
+  shell: "HELM_HOME={{ caas.helm_home }} helm init -c --skip-refresh"
+
+- name: add the chart-repo to helm repositories
+  shell: "HELM_HOME={{ caas.helm_home }} /usr/bin/helm repo add default {{ caas.chart_repo }}/charts"
+  register: res
+  until: res.stdout | search('has been added to your repositories')
+  retries: 3
+  delay: 5
diff --git a/ansible/roles/helm/tasks/main.yml b/ansible/roles/helm/tasks/main.yml
new file mode 100644 (file)
index 0000000..17d4117
--- /dev/null
@@ -0,0 +1,60 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: Add tiller manifest template manifest
+  template:
+    src: tiller.yml
+    dest: "{{ caas.manifests_directory }}/tiller.yml"
+
+- name: Add tiller service
+  template:
+    src: tiller-service.yml
+    dest: "{{ caas.manifests_directory }}/tiller-service.yml"
+
+- name: create deployment api object
+  kubectl:
+    manifest: "{{ caas.manifests_directory }}/tiller.yml"
+    state: present
+  when: nodename | search("caas_master1")
+
+- name: create tiller service
+  kubectl:
+    manifest: "{{ caas.manifests_directory }}/tiller-service.yml"
+    state: present
+  when: nodename | search("caas_master1")
+
+- name: make env vars permanent
+  lineinfile:
+    dest: /etc/profile
+    state: present
+    line: "{{ item }}"
+    regexp: "{{ item }}"
+  with_items:
+    - "export HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }}"
+    - "export HELM_HOME={{ caas.helm_home }}"
+  become_user: "root"
+
+- name: make env vars permanent
+  lineinfile:
+    dest: /etc/environment
+    state: present
+    line: "{{ item }}"
+    regexp: "{{ item }}"
+  with_items:
+    - "HELM_HOST={{ caas.tiller_ip }}:{{ caas.tiller_port }}"
+    - "HELM_HOME={{ caas.helm_home }}"
+  become_user: "root"
+
+- import_tasks: config.yml
diff --git a/ansible/roles/helm/templates/tiller-service.yml b/ansible/roles/helm/templates/tiller-service.yml
new file mode 100644 (file)
index 0000000..7f53970
--- /dev/null
@@ -0,0 +1,31 @@
+{#
+Copyright 2019 Nokia
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  labels:
+    {{ caas.kubernetes_component_label }}: tiller
+  name: tiller
+  namespace: kube-system
+spec:
+  clusterIP: {{ caas.tiller_ip }}
+  ports:
+    - name: tiller1
+      port: {{ caas.tiller_port }}
+      targetPort: {{ caas.tiller_port }}
+  selector:
+    {{ caas.kubernetes_component_label }}: tiller
diff --git a/ansible/roles/helm/templates/tiller.yml b/ansible/roles/helm/templates/tiller.yml
new file mode 100644 (file)
index 0000000..507a6da
--- /dev/null
@@ -0,0 +1,52 @@
+{#
+Copyright 2019 Nokia
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+#}
+---
+apiVersion: apps/v1beta2
+kind: Deployment
+metadata:
+  name: tiller
+  namespace: kube-system
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      {{ caas.kubernetes_component_label }}: tiller
+  template:
+    metadata:
+      annotations:
+        danm.k8s.io/interfaces: |
+          [
+            {
+              "network":"flannel"
+            }
+          ]
+      labels:
+        {{ caas.kubernetes_component_label }}: tiller
+    spec:
+      dnsPolicy: ClusterFirst
+      nodeSelector:
+        nodename: caas_master1
+      securityContext:
+        runAsUser: {{ caas.uid.kube }}
+      containers:
+        - name: tiller
+          image: {{ container_image_names | select('search', '/tiller') | list | last }}
+          env:
+            - name: INTERFACE_NAME
+              value: "{{ caas.internal_flannel_interface }}"
+            - name: TILLER_PORT
+              value: "{{ caas.tiller_port }}"
+      serviceAccountName: tiller
diff --git a/docker-build/chartrepohandler/Dockerfile b/docker-build/chartrepohandler/Dockerfile
new file mode 100644 (file)
index 0000000..db99275
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM alpine:3.9
+MAINTAINER Krisztian Lengyel <krisztian.lengyel@nokia.com>
+
+COPY mainstart.sh /usr/bin/mainstart.sh
+COPY chart-repo-handler /chart-repo-handler
+ENV GOPATH /build
+
+# TODO remake build
+RUN adduser -u 150 -D -H chartrepo \
+&& apk add --no-cache --virtual .build-deps go gcc g++ git glide \
+&& apk add --no-cache curl \
+&& mkdir -p $GOPATH/src \
+&& mv /chart-repo-handler $GOPATH/src/chart-repo-handler \
+&& cd $GOPATH/src/chart-repo-handler \
+&& chmod +x $GOPATH/src/chart-repo-handler/build.sh \
+&& $GOPATH/src/chart-repo-handler/build.sh \
+&& cp chart-repo-handler /usr/bin/chart-repo-handler \
+&& rm -rf $GOPATH \
+&& apk del .build-deps \
+&& rm -rf /root/.glide \
+&& chown -R chartrepo /usr/bin/mainstart.sh \
+&& chmod +x /usr/bin/mainstart.sh
+
+ENTRYPOINT /usr/bin/mainstart.sh
diff --git a/docker-build/chartrepohandler/bom.json b/docker-build/chartrepohandler/bom.json
new file mode 100644 (file)
index 0000000..86c9e0e
--- /dev/null
@@ -0,0 +1,286 @@
+{
+  "bom": [
+    {
+      "name": "alpine-linux-container",
+      "version": "3.9",
+      "source-url": "https://github.com/gliderlabs/docker-alpine/archive/c4f4c7a6e14d6efeb9a160da464717e03d2cc3ee.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "musl",
+      "version": "1.1.20-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/musl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "busybox",
+      "version": "1.29.3-r10",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/busybox/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "alpine-baselayout",
+      "version": "3.1.0-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-baselayout/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "alpine-keys",
+      "version": "2.1-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-keys/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libcrypto1.1",
+      "version": "1.1.1a-r1",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libssl1.1",
+      "version": "1.1.1a-r1",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ca-certificates-cacert",
+      "version": "20190108-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ca-certificates/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libtls-standalone",
+      "version": "2.7.4-r6",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/libtls-standalone/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ssl_client",
+      "version": "1.29.3-r10",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/busybox/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "zlib",
+      "version": "1.2.11-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/zlib/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "apk-tools",
+      "version": "2.10.3-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/apk-tools/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "scanelf",
+      "version": "1.2.3-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/pax-utils/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "musl-utils",
+      "version": "1.1.20-r3",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/musl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libc-utils",
+      "version": "0.7.1-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libc-dev/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libbz2",
+      "version": "1.0.6-r6",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/bzip2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "expat",
+      "version": "2.2.6-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/expat/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libffi",
+      "version": "3.2.1-r6",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libffi/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "gdbm",
+      "version": "1.13-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/gdbm/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-terminfo-base",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-terminfo",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-libs",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "readline",
+      "version": "7.0.003-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/readline/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "sqlite-libs",
+      "version": "3.26.0-r3",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/sqlite/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "python2",
+      "version": "2.7.15-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/python2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "py-setuptools",
+      "version": "40.6.3-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py-setuptools/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "py2-pip",
+      "version": "18.1-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py2-pip/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ca-certificates",
+      "version": "20190108-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/ca-certificates/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "nghttp2-libs",
+      "version": "1.35.1-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/nghttp2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libssh2",
+      "version": "1.8.0-r4",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libssh2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libcurl",
+      "version": "7.63.0-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/curl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "curl",
+      "version": "7.63.0-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/curl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "pip",
+      "version": "19.0.2",
+      "source-url": "https://github.com/pypa/pip/archive/19.0.2.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "setuptools",
+      "version": "40.6.3.post20190116",
+      "source-url": "https://github.com/pypa/setuptools/archive/v40.6.3.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-ghodss-yaml",
+      "version": "c7ce16629ff4cd059ed96ed06419dd3856fd3577",
+      "source-url": "https://github.com/ghodss/yaml/archive/c7ce16629ff4cd059ed96ed06419dd3856fd3577.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-gobwas-glob",
+      "version": "e7a84e9525fe90abcda167b604e483cc959ad4aa",
+      "source-url": "https://github.com/gobwas/glob/archive/e7a84e9525fe90abcda167b604e483cc959ad4aa.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-golang-protobuf",
+      "version": "1d3f30b51784bec5aad268e59fd3c2fc1c2fe73f",
+      "source-url": "https://github.com/golang/protobuf/archive/1d3f30b51784bec5aad268e59fd3c2fc1c2fe73f.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-gorilla-context",
+      "version": "51ce91d2eaddeca0ef29a71d766bb3634dadf729",
+      "source-url": "https://github.com/gorilla/context/archive/51ce91d2eaddeca0ef29a71d766bb3634dadf729.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-gorilla-mux",
+      "version": "392c28fe23e1c45ddba891b0320b3b5df220beea",
+      "source-url": "https://github.com/gorilla/mux/archive/392c28fe23e1c45ddba891b0320b3b5df220beea.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-kelseyhightower-envconfig",
+      "version": "dd1402a4d99de9ac2f396cd6fcb957bc2c695ec1",
+      "source-url": "https://github.com/kelseyhightower/envconfig/archive/dd1402a4d99de9ac2f396cd6fcb957bc2c695ec1.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-Masterminds-semver",
+      "version": "c84ddcca87bf5a941b138dde832a7e20b0159ad8",
+      "source-url": "https://github.com/Masterminds/semver/archive/c84ddcca87bf5a941b138dde832a7e20b0159ad8.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-ncw-swift",
+      "version": "6f342da371d063863f2f354f183e4ab0ef72d287",
+      "source-url": "https://github.com/ncw/swift/archive/6f342da371d063863f2f354f183e4ab0ef72d287.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-x-crypto",
+      "version": "505ab145d0a99da450461ae2c1a9f6cd10d1f447",
+      "source-url": "https://github.com/golang/crypto/archive/505ab145d0a99da450461ae2c1a9f6cd10d1f447.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-go-yaml-yaml",
+      "version": "51d6538a90f86fe93ac480b35f37b2be17fef232",
+      "source-url": "https://github.com/go-yaml/yaml/archive/51d6538a90f86fe93ac480b35f37b2be17fef232.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-k8s-io-apimachinery",
+      "version": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22",
+      "source-url": "https://github.com/kubernetes/apimachinery/archive/57dc7e687b5426ecb5df4cabdcdce30fddb74f22.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-k8s-io-helm",
+      "version": "1402a4d6ec9fb349e17b912e32fe259ca21181e3",
+      "source-url": "https://github.com/helm/helm/archive/1402a4d6ec9fb349e17b912e32fe259ca21181e3.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "go-k8s-io-kubernetes",
+      "version": "83ba7bfd499145e514dc65fdb48a00b7e1ce6fc7",
+      "source-url": "https://github.com/kubernetes/kubernetes/archive/83ba7bfd499145e514dc65fdb48a00b7e1ce6fc7.tar.gz",
+      "foss": "yes"
+    }
+  ]
+}
diff --git a/docker-build/chartrepohandler/mainstart.sh b/docker-build/chartrepohandler/mainstart.sh
new file mode 100644 (file)
index 0000000..ddef447
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LISTENONIP=`ifconfig ${CHARTREPOHANDLER_LISTENONINTERFACE} | awk '/inet addr/{print substr($2,6)}'`
+export CHARTREPOHANDLER_LISTENONIP=${LISTENONIP}
+exec /usr/bin/chart-repo-handler
diff --git a/docker-build/helm-builder/Dockerfile b/docker-build/helm-builder/Dockerfile
new file mode 100644 (file)
index 0000000..2b1ff95
--- /dev/null
@@ -0,0 +1,44 @@
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM centos:7.6.1810
+MAINTAINER Krisztian Lengyel <krisztian.lengyel@nokia.com>
+
+ARG HELM_VERSION
+ARG go_version
+ARG binaries
+ARG go_install_dir="/usr/local/go"
+
+ENV GOBIN=/usr/local/bin
+ENV GOPATH /build
+ARG build_packages="gcc gcc-c++ glibc-devel make autoconf git which libtool"
+ENV PATH="$GOPATH/bin:$go_install_dir/bin:$PATH"
+
+RUN yum install -y --setopt=skip_missing_names_on_install=False \
+      ${build_packages} \
+&&  mkdir -p $go_install_dir \
+&&  curl -fsSL -k https://dl.google.com/go/go${go_version}.linux-amd64.tar.gz | tar zx --strip-components=1 -C ${go_install_dir} \
+\
+# Build Helm
+&&  mkdir -p $GOPATH/src/k8s.io \
+&&  cd $GOPATH/src/k8s.io \
+&&  git clone https://github.com/kubernetes/helm.git \
+&&  cd helm \
+&&  make GIT_TAG=v${HELM_VERSION} bootstrap build-cross \
+&&  mkdir -p ${binaries} \
+&&  mv ./_dist/linux-amd64/tiller ${binaries}/ \
+&&  mv ./_dist/linux-amd64/helm ${binaries}/ \
+&&  rm -rf $GOPATH \
+&&  rm -rf /build \
+&&  rm -rf /root/.glide
diff --git a/docker-build/tiller/Dockerfile b/docker-build/tiller/Dockerfile
new file mode 100644 (file)
index 0000000..0069ebc
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM alpine:3.9
+MAINTAINER Krisztian Lengyel <krisztian.lengyel@nokia.com>
+
+COPY mainstart.sh /usr/bin/mainstart.sh
+COPY tiller /usr/bin/tiller
+
+RUN adduser -u 144 -D -H -s /sbin/nologin kube \
+&&  mkdir -p /home/kube \
+&&  chown -R kube:kube /home/kube \
+&&  chmod a+x /usr/bin/tiller /usr/bin/mainstart.sh
+
+ENTRYPOINT ["/usr/bin/mainstart.sh"]
diff --git a/docker-build/tiller/bom.json b/docker-build/tiller/bom.json
new file mode 100644 (file)
index 0000000..30dff0e
--- /dev/null
@@ -0,0 +1,214 @@
+{
+  "bom": [
+    {
+      "name": "alpine-linux-container",
+      "version": "3.9",
+      "source-url": "https://github.com/gliderlabs/docker-alpine/archive/c4f4c7a6e14d6efeb9a160da464717e03d2cc3ee.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "musl",
+      "version": "1.1.20-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/musl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "busybox",
+      "version": "1.29.3-r10",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/busybox/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "alpine-baselayout",
+      "version": "3.1.0-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-baselayout/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "alpine-keys",
+      "version": "2.1-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-keys/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libcrypto1.1",
+      "version": "1.1.1a-r1",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libssl1.1",
+      "version": "1.1.1a-r1",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ca-certificates-cacert",
+      "version": "20190108-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ca-certificates/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libtls-standalone",
+      "version": "2.7.4-r6",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/libtls-standalone/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ssl_client",
+      "version": "1.29.3-r10",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/busybox/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "zlib",
+      "version": "1.2.11-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/zlib/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "apk-tools",
+      "version": "2.10.3-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/apk-tools/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "scanelf",
+      "version": "1.2.3-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/pax-utils/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "musl-utils",
+      "version": "1.1.20-r3",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/musl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libc-utils",
+      "version": "0.7.1-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libc-dev/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libbz2",
+      "version": "1.0.6-r6",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/bzip2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "expat",
+      "version": "2.2.6-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/expat/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libffi",
+      "version": "3.2.1-r6",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libffi/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "gdbm",
+      "version": "1.13-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/gdbm/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-terminfo-base",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-terminfo",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ncurses-libs",
+      "version": "6.1_p20190105-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "readline",
+      "version": "7.0.003-r1",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/readline/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "sqlite-libs",
+      "version": "3.26.0-r3",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/sqlite/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "python2",
+      "version": "2.7.15-r3",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/python2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "py-setuptools",
+      "version": "40.6.3-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py-setuptools/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "py2-pip",
+      "version": "18.1-r0",
+      "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py2-pip/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "ca-certificates",
+      "version": "20190108-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/ca-certificates/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "nghttp2-libs",
+      "version": "1.35.1-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/nghttp2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libssh2",
+      "version": "1.8.0-r4",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/libssh2/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "libcurl",
+      "version": "7.63.0-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/curl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "curl",
+      "version": "7.63.0-r0",
+      "source-url": "https://git.alpinelinux.org/aports/tree/main/curl/APKBUILD?h=3.9-stable",
+      "foss": "yes"
+    },
+    {
+      "name": "pip",
+      "version": "19.0.2",
+      "source-url": "https://github.com/pypa/pip/archive/19.0.2.tar.gz",
+      "foss": "yes"
+    },    
+    {
+      "name": "setuptools",
+      "version": "40.6.3.post20190116",
+      "source-url": "https://github.com/pypa/setuptools/archive/v40.6.3.tar.gz",
+      "foss": "yes"
+    },
+    {
+      "name": "helm",
+      "version": "2.12.3",
+      "source-url": "https://github.com/helm/helm/archive/v2.12.3.tar.gz",
+      "foss": "yes"
+    }
+  ]
+}
diff --git a/docker-build/tiller/mainstart.sh b/docker-build/tiller/mainstart.sh
new file mode 100755 (executable)
index 0000000..86cc793
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+ip_addr=`ip -4 addr list ${INTERFACE_NAME} | awk '$1 ~ /^inet/ { sub("/.*", "", $2); print $2 }'`
+exec /usr/bin/tiller -listen=${ip_addr}:${TILLER_PORT}
diff --git a/src/chart-repo-handler/.gitignore b/src/chart-repo-handler/.gitignore
new file mode 100644 (file)
index 0000000..c69ed5b
--- /dev/null
@@ -0,0 +1,2 @@
+vendor/
+
diff --git a/src/chart-repo-handler/README.md b/src/chart-repo-handler/README.md
new file mode 100644 (file)
index 0000000..50a4ece
--- /dev/null
@@ -0,0 +1,22 @@
+# Chart Repo Handler - a swift http frontend for helm
+This project aims to let unmodified http clients to access Openstack Swift object store.
+Furthermore it acts as a helm chart repo with storage capabilities.
+
+## Motivation
+The motivation is that usually object stores (like S3) has API for static HTTP content hosting for standard HTTP clients (like web browsers). As Swift uses custom HTTP headers for authentication, it is not working OOTB.
+This swift behavior makes impossible to use swift directly with helm so this project is a middle layer between them.
+
+## Usage
+The frontend is configured through environment variables. These are the credentials for the object store and the targeted container in it.
+To enable TLS for Swift backend, use https in AUTHURL and set the location of RootCA pem file in the TLSCAPATH variable.
+See env.sh for a sample.
+
+
+## Details
+* Written in go, targeted to be a 12 factor app
+* Uses ncw/swift as the most mature client API towards the Swift object store
+* Uses gorilla/mux to decode HTTP requests
+* Borrows some of the helm packages to maintain index.yaml file for the charts
+
+
+This work is licensed under a Creative Commons Attribution 4.0 International License.
diff --git a/src/chart-repo-handler/build.sh b/src/chart-repo-handler/build.sh
new file mode 100644 (file)
index 0000000..b0b1295
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+which glide >/dev/null
+if [ $? -ne 0 ]; then
+       go get -v github.com/Masterminds/glide
+fi
+which git >/dev/null
+if [ $? -ne 0 ]; then
+       apk add --no-cache git
+fi
+ORIGPATH=`pwd`
+TARGETPATH=`dirname $(readlink -f $0)`
+cd $TARGETPATH
+pwd
+glide install
+ln -s $TARGETPATH/pkg $TARGETPATH/vendor/pkg
+go build -v
+cd $ORIGPATH
+
diff --git a/src/chart-repo-handler/env.sh b/src/chart-repo-handler/env.sh
new file mode 100644 (file)
index 0000000..81de15e
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+export CHARTREPOHANDLER_AUTHKEY=58a2c1331a572c1b69c4
+export CHARTREPOHANDLER_AUTHUSER=admin:admin
+export CHARTREPOHANDLER_AUTHURL=http://172.24.16.101:8081/auth/v1.0/
+export CHARTREPOHANDLER_CONTAINER=packages
+export CHARTREPOHANDLER_LISTENONPORT=8088
+export CHARTREPOHANDLER_LISTENONIP=0.0.0.0
+export CHARTREPOHANDLER_REPOURL=chart-repo.nokia.net
+export CHARTREPOHANDLER_INDEXPATH=charts
+export CHARTREPOHANDLER_TLSCERTPATH=/etc/etcd/ssl/etcd1.pem
+export CHARTREPOHANDLER_TLSKEYPATH=/etc/etcd/ssl/etcd1-key.pem
+export CHARTREPOHANDLER_TLSCAPATH=/etc/chart-repo/cacert.pem
diff --git a/src/chart-repo-handler/glide.lock b/src/chart-repo-handler/glide.lock
new file mode 100644 (file)
index 0000000..7c414a1
--- /dev/null
@@ -0,0 +1,78 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+hash: b560dfd277fb6f11ca0591ea08ca8b9f07ce90b21428e547c62d90238a03d1ea
+updated: 2017-03-14T09:50:45.567193043+08:00
+imports:
+- name: github.com/blang/semver
+  version: 31b736133b98f26d5e078ec9eb591666edfd091f
+- name: github.com/ghodss/yaml
+  version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
+- name: github.com/gobwas/glob
+  version: bea32b9cd2d6f55753d94a28e959b13f0244797a
+  subpackages:
+  - compiler
+  - match
+  - syntax
+  - syntax/ast
+  - syntax/lexer
+  - util/runes
+  - util/strings
+- name: github.com/golang/glog
+  version: 44145f04b68cf362d9c4df2182967c2275eaefed
+- name: github.com/golang/protobuf
+  version: df1d3ca07d2d07bba352d5b73c4313b4e2a6203e
+  subpackages:
+  - proto
+  - ptypes/any
+  - ptypes/timestamp
+- name: github.com/gorilla/context
+  version: 08b5f424b9271eedf6f9f0ce86cb9396ed337a42
+- name: github.com/gorilla/mux
+  version: 392c28fe23e1c45ddba891b0320b3b5df220beea
+- name: github.com/kelseyhightower/envconfig
+  version: 8bf4bbfc795e2c7c8a5ea47b707453ed019e2ad4
+- name: github.com/Masterminds/semver
+  version: 59c29afe1a994eacb71c833025ca7acf874bb1da
+- name: github.com/ncw/swift
+  version: 6c1b1510538e1f00d49a558b7b9b87d71bc454d6
+- name: golang.org/x/crypto
+  version: 1f22c0103821b9390939b6776727195525381532
+  subpackages:
+  - cast5
+  - openpgp
+  - openpgp/armor
+  - openpgp/clearsign
+  - openpgp/elgamal
+  - openpgp/errors
+  - openpgp/packet
+  - openpgp/s2k
+- name: gopkg.in/yaml.v2
+  version: a83829b6f1293c91addabc89d0571c246397bbf4
+- name: k8s.io/helm
+  version: 1b330722aafcb8123114ae51f69d1e884a326f3e
+  subpackages:
+  - pkg/chartutil
+  - pkg/ignore
+  - pkg/proto/hapi/chart
+  - pkg/proto/hapi/version
+  - pkg/provenance
+  - pkg/repo
+  - pkg/tlsutil
+  - pkg/urlutil
+- name: k8s.io/kubernetes
+  version: e9eeec655e7fdee50d4e19200f9707d1cd4a3371
+  subpackages:
+  - pkg/version
+testImports: []
diff --git a/src/chart-repo-handler/glide.yaml b/src/chart-repo-handler/glide.yaml
new file mode 100644 (file)
index 0000000..ef91cc4
--- /dev/null
@@ -0,0 +1,25 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+package: .
+ignore:
+- pkg
+import:
+- package: github.com/gorilla/mux
+  version: ~1.3.0
+- package: github.com/ncw/swift
+- package: github.com/kelseyhightower/envconfig
+- package: k8s.io/helm
+  version: ~2.2
diff --git a/src/chart-repo-handler/main.go b/src/chart-repo-handler/main.go
new file mode 100644 (file)
index 0000000..5cf35b4
--- /dev/null
@@ -0,0 +1,159 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+  "crypto/tls"
+  "log"
+  "net/http"
+  "pkg/api"
+  "pkg/config"
+  "pkg/repo"
+  "github.com/kelseyhightower/envconfig"
+  "github.com/ncw/swift"
+  "os"
+  "os/signal"
+  "syscall"
+  "strconv"
+  "time"
+  "errors"
+  "crypto/x509"
+  "io/ioutil"
+)
+
+var (
+  chartRepo *http.Server
+)
+
+const (
+  regenRetryCounter = 10
+)
+
+func main() {
+  var envConfig config.EnvConfig
+  err := envconfig.Process("chartrepohandler", &envConfig)
+  if err != nil {
+    log.Fatal(err.Error())
+    }
+
+  swiftCon := connectSwift(envConfig)
+  log.Println("Chart repo handler v0.9 started up.")
+  log.Printf("Config: %s\n", envConfig.ToString())
+  log.Println("Regenerating index for:", envConfig.IndexPath)
+  if err := regenerateIndexYaml(envConfig, &swiftCon); err != nil {
+    log.Println(err.Error())
+    os.Exit(-1)
+    }
+  startHttpServer(envConfig, &swiftCon)
+  signalChan := make(chan os.Signal, 1)
+  signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
+  for {
+    select {
+      case <-signalChan:
+        log.Println("Shutdown signal received, exiting...")
+        if (chartRepo != nil) {
+          chartRepo.Close()
+          }
+        os.Exit(0)
+    }
+  }
+}
+
+func connectSwift(envConfig config.EnvConfig) swift.Connection {
+  swiftCon := swift.Connection{
+    UserName:  envConfig.AuthUser,
+    ApiKey:    envConfig.AuthKey,
+    AuthUrl:   envConfig.AuthUrl,
+    }
+  if envConfig.TlsCaPath != "" {
+    log.Printf("INFO: TlsCaPath is presented: Trying to enforce TLS Authentication on swift backend using the server certs")
+    file, err := ioutil.ReadFile(envConfig.TlsCaPath)
+    if err != nil {
+      log.Fatal(err)
+      log.Printf("Wrong or missing value in paramteter: TlsCaPath")
+      os.Exit(-1)
+      }
+    certPool := x509.NewCertPool()
+    ok := certPool.AppendCertsFromPEM([]byte(file))
+    if !ok {
+      log.Fatal("Corrupt CACert file")
+      os.Exit(-1)
+      }
+    cert, err := tls.LoadX509KeyPair(envConfig.TlsCertPath, envConfig.TlsKeyPath)
+    if err != nil {
+      log.Fatal(err)
+      log.Printf("Wrong or missing value in paramteter: TlsCertPath or TlsKeyPath")
+      os.Exit(-1)
+      }
+    swiftCon.Transport = &http.Transport{
+      TLSClientConfig: &tls.Config{
+        RootCAs: certPool,
+        Certificates: []tls.Certificate{cert}, 
+        },
+      }
+    }
+  return swiftCon
+}
+
+func regenerateIndexYaml(envConfig config.EnvConfig, swiftConn *swift.Connection) error {
+  var err error
+  for i := 0; i <= regenRetryCounter; i++ {
+    err = repo.Index(swiftConn, envConfig.Container, envConfig.RepoUrl+":"+envConfig.ListenOnPort, envConfig.IndexPath, "/index.yaml")
+    if err != nil {
+      log.Println("INFO: Regenerating index.yaml in Swift try no.: " + strconv.Itoa(i) + " was unsuccessful at: " + swiftConn.AuthUrl +
+                  " with error:" + err.Error())
+      time.Sleep(10 * time.Second)
+      continue
+    } else {
+      return nil
+    }
+  }
+  return errors.New("ERROR: Swift is not responsive, giving-up regeneration!")
+}
+
+func startHttpServer(envConfig config.EnvConfig, swiftConn *swift.Connection) {
+  router := api.NewRouter(swiftConn, envConfig)
+  var tlsCfg *tls.Config
+  if envConfig.TlsCertPath != "" && envConfig.TlsKeyPath != "" {
+    log.Println("TLS used")
+    tlsCfg = &tls.Config{
+      MinVersion:               tls.VersionTLS12,
+      CurvePreferences:         []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
+      PreferServerCipherSuites: true,
+      CipherSuites: []uint16{
+        tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
+        tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
+        tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
+        tls.TLS_RSA_WITH_AES_256_CBC_SHA,
+      },
+    }
+  } else {
+    tlsCfg = &tls.Config{}
+  }
+  chartRepo = &http.Server{
+    Addr:         envConfig.ListenOnIP + ":" + envConfig.ListenOnPort,
+    Handler:      router,
+    TLSConfig:    tlsCfg,
+    TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0),
+  }
+  go func() {
+    if chartRepo.TLSConfig != nil {
+      log.Fatal(chartRepo.ListenAndServeTLS(envConfig.TlsCertPath, envConfig.TlsKeyPath))
+    } else {
+      log.Fatal(chartRepo.ListenAndServe())
+    }
+  }()
+}
+
diff --git a/src/chart-repo-handler/pkg/api/handlers.go b/src/chart-repo-handler/pkg/api/handlers.go
new file mode 100644 (file)
index 0000000..1791bbb
--- /dev/null
@@ -0,0 +1,122 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package api
+
+import (
+       "fmt"
+       "io"
+       "log"
+       "net/http"
+       "strings"
+
+       "pkg/config"
+       "pkg/repo"
+
+       "github.com/gorilla/mux"
+       "github.com/ncw/swift"
+)
+
+func Index(c *swift.Connection, config config.EnvConfig) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               fmt.Fprintln(w, "<html><body>")
+               fmt.Fprintln(w, "Hello World!<br />")
+               objects, err := c.ObjectNames(config.Container, nil)
+               if err != nil {
+                       log.Println("Index error:", err)
+                       fmt.Fprintln(w, "Index error:", err)
+               } else {
+                       for _, v := range objects {
+                               fmt.Fprintf(w, "<a href=\"%s\">%s</a><br />", v, v)
+                       }
+               }
+               fmt.Fprintln(w, "</body></html>")
+       }
+}
+
+func ObjectGet(c *swift.Connection, config config.EnvConfig) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               vars := mux.Vars(r)
+               objectName := vars["id"]
+
+               object, _, err := c.ObjectOpen(config.Container, objectName, false, nil)
+
+               if err != nil {
+                       switch err.Error() {
+                       case "Object Not Found":
+                               w.WriteHeader(http.StatusNotFound)
+                       default:
+                               w.WriteHeader(http.StatusInternalServerError)
+                       }
+                       log.Println("ObjectGet error:", err, ", requested object:", objectName)
+                       fmt.Fprintln(w, "<html><body>")
+                       fmt.Fprintln(w, "ObjectGet error:", err)
+                       fmt.Fprintln(w, "</body></html>")
+                       return
+               }
+               io.Copy(w, object)
+               object.Close()
+       }
+}
+
+func ObjectPut(c *swift.Connection, config config.EnvConfig) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               vars := mux.Vars(r)
+               objectName := vars["id"]
+
+               _, err := c.ObjectPut(config.Container, objectName, r.Body, false, "", "", nil)
+               if err != nil {
+                       log.Println("ObjectPut error:", err.Error())
+                       w.WriteHeader(http.StatusInternalServerError)
+                       fmt.Fprintln(w, "<html><body>")
+                       fmt.Fprintln(w, "ObjectPut error:", err)
+                       fmt.Fprintln(w, "</body></html>")
+                       return
+               }
+               if strings.HasPrefix(objectName, config.IndexPath) && strings.HasSuffix(objectName, "tgz") {
+                       log.Println("Regenerating index for:", config.IndexPath)
+                       if err := repo.Index(c, config.Container, config.RepoUrl+":"+config.ListenOnPort, config.IndexPath, "/index.yaml"); err != nil {
+                               log.Println("ObjectPut error:", err.Error())
+                               fmt.Fprintln(w, "<html><body>")
+                               fmt.Fprintln(w, "Index file generation error:", err)
+                               fmt.Fprintln(w, "</body></html>")
+                       }
+               }
+       }
+}
+
+func ObjectDelete(c *swift.Connection, config config.EnvConfig) http.HandlerFunc {
+       return func(w http.ResponseWriter, r *http.Request) {
+               vars := mux.Vars(r)
+               objectName := vars["id"]
+
+               err := c.ObjectDelete(config.Container, objectName)
+               if err != nil {
+                       log.Println("ObjectDelete error:", err.Error())
+                       fmt.Fprintln(w, "<html><body>")
+                       fmt.Fprintln(w, "ObjectDelete error:", err)
+                       fmt.Fprintln(w, "</body></html>")
+                       return
+               }
+               if strings.HasPrefix(objectName, config.IndexPath) && strings.HasSuffix(objectName, "tgz") {
+                       log.Println("Regenerating index for:", config.IndexPath)
+                       if err := repo.Index(c, config.Container, config.RepoUrl+":"+config.ListenOnPort, config.IndexPath, "/index.yaml"); err != nil {
+                               log.Println("ObjectPut error:", err.Error())
+                               fmt.Fprintln(w, "<html><body>")
+                               fmt.Fprintln(w, "Index file generation error:", err)
+                               fmt.Fprintln(w, "</body></html>")
+                       }
+               }
+       }
+}
diff --git a/src/chart-repo-handler/pkg/api/logger.go b/src/chart-repo-handler/pkg/api/logger.go
new file mode 100644 (file)
index 0000000..1305ac4
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package api
+
+import (
+       "log"
+       "net/http"
+       "time"
+)
+
+func Logger(inner http.Handler, name string) http.Handler {
+       return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+               start := time.Now()
+
+               inner.ServeHTTP(w, r)
+
+               log.Printf(
+                       "%s %s %s %s",
+                       r.Method,
+                       r.RequestURI,
+                       name,
+                       time.Since(start),
+               )
+       })
+}
diff --git a/src/chart-repo-handler/pkg/api/routers.go b/src/chart-repo-handler/pkg/api/routers.go
new file mode 100644 (file)
index 0000000..d5c5e81
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package api
+
+import (
+       "net/http"
+       "pkg/config"
+
+       "github.com/gorilla/mux"
+       "github.com/ncw/swift"
+)
+
+type Route struct {
+       Name        string
+       Method      string
+       Pattern     string
+       HandlerFunc func(*swift.Connection, config.EnvConfig) http.HandlerFunc
+}
+
+type Routes []Route
+
+var routes = Routes{
+       Route{
+               "Index",
+               "GET",
+               "/",
+               Index,
+       },
+
+       Route{
+               "ObjectGet",
+               "GET",
+               // tonyaw: make it can match slash, such as "aaa/bbb"
+               "/{id:.*}",
+               ObjectGet,
+       },
+       Route{
+               "ObjectPut",
+               "POST",
+               // tonyaw: make it can match slash, such as "aaa/bbb"
+               "/{id:.*}",
+               ObjectPut,
+       },
+       Route{
+               "ObjectPut",
+               "PUT",
+               // tonyaw: make it can match slash, such as "aaa/bbb"
+               "/{id:.*}",
+               ObjectPut,
+       },
+       Route{
+               "ObjectDelete",
+               "DELETE",
+               "/{id:.*}",
+               ObjectDelete,
+       },
+}
+
+func NewRouter(c *swift.Connection, config config.EnvConfig) *mux.Router {
+       router := mux.NewRouter().StrictSlash(true)
+       for _, route := range routes {
+               var handler http.Handler
+               handler = route.HandlerFunc(c, config)
+               handler = Logger(handler, route.Name)
+
+               router.
+                       Methods(route.Method).
+                       Path(route.Pattern).
+                       Name(route.Name).
+                       Handler(handler)
+       }
+
+       return router
+}
diff --git a/src/chart-repo-handler/pkg/chartutil/load.go b/src/chart-repo-handler/pkg/chartutil/load.go
new file mode 100644 (file)
index 0000000..fba4b64
--- /dev/null
@@ -0,0 +1,71 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// tonyaw: refer to "kubernetes/helm/pkg/chartutil/load.go"
+package chartutil
+
+import (
+       "k8s.io/helm/pkg/proto/hapi/chart"
+
+       // tonyaw:
+       helm_chartutil "k8s.io/helm/pkg/chartutil"
+       "github.com/ncw/swift"
+)
+
+// Load takes a string name, tries to resolve it to a file or directory, and then loads it.
+//
+// This is the preferred way to load a chart. It will discover the chart encoding
+// and hand off to the appropriate chart reader.
+//
+// If a .helmignore file is present, the directory loader will skip loading any files
+// matching it. But .helmignore is not evaluated when reading out of an archive.
+func Load(c *swift.Connection, container, name string) (*chart.Chart, error) {
+       // tonyaw.TBD: ignore dir case for now.
+       // fi, err := os.Stat(name)
+       // if err != nil {
+       //      return nil, err
+       // }
+       // if fi.IsDir() {
+       //      return LoadDir(name)
+       // }
+       return LoadFile(c, container, name)
+}
+
+
+// LoadFile loads from an archive file.
+func LoadFile(c *swift.Connection, container, name string) (*chart.Chart, error) {
+       // tonyaw.TBD: ignore dir case for now.
+       // if fi, err := os.Stat(name); err != nil {
+       //      return nil, err
+       // } else if fi.IsDir() {
+       //      return nil, errors.New("cannot load a directory")
+       // }
+
+       object, _, err := c.ObjectOpen(container, name, false, nil)
+       if err != nil {
+               return nil, err
+       }
+       defer object.Close()
+
+       return helm_chartutil.LoadArchive(object)
+}
+
+
+// LoadDir loads from a directory.
+//
+// This loads charts only from directories.
+// tonyaw.TBD: do we still need "LoadDir" for swift?
+func LoadDir(dir string) (*chart.Chart, error) {
+       return nil, nil
+}
diff --git a/src/chart-repo-handler/pkg/config/config.go b/src/chart-repo-handler/pkg/config/config.go
new file mode 100644 (file)
index 0000000..cdc8a2a
--- /dev/null
@@ -0,0 +1,46 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package config
+
+type EnvConfig struct {
+       AuthUser     string `required:"true"`
+       AuthKey      string `required:"true"`
+       AuthUrl      string `required:"true"`
+       Container    string `required:"true"`
+       ListenOnIP   string `required:"true"`
+       ListenOnPort string `required:"true"`
+       RepoUrl      string `required:"true"`
+       IndexPath    string
+       TlsCertPath  string
+       TlsKeyPath   string
+       TlsCaPath   string
+}
+
+func (c *EnvConfig) ToString() string {
+       result := "AuthUser=" + c.AuthUser
+       result += " AuthKey=***"
+       result += " AuthUrl=" + c.AuthUrl
+       result += " Container=" + c.Container
+       result += " ListenOnIP=" + c.ListenOnIP
+       result += " ListenOnPort=" + c.ListenOnPort
+       result += " RepoUrl=" + c.RepoUrl
+       result += " IndexPath=" + c.IndexPath
+       result += " TlsCertPath=" + c.TlsCertPath
+       result += " TlsKeyPath=" + c.TlsKeyPath
+       result += " TlsCaPath" + c.TlsCaPath
+
+       return result
+}
+
diff --git a/src/chart-repo-handler/pkg/repo/index.go b/src/chart-repo-handler/pkg/repo/index.go
new file mode 100644 (file)
index 0000000..cdf6465
--- /dev/null
@@ -0,0 +1,161 @@
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// tonyaw: refer to "kubernetes/helm/pkg/repo/index.go"
+package repo
+
+import (
+       "path/filepath"
+       "strings"
+       "time"
+
+       "github.com/ghodss/yaml"
+
+       // tonyaw: added import
+       "log"
+       "pkg/chartutil"
+
+       "github.com/ncw/swift"
+       "k8s.io/helm/pkg/provenance"
+       helm_repo "k8s.io/helm/pkg/repo"
+       "k8s.io/helm/pkg/urlutil"
+)
+
+//var IndexPath = "index.yaml"
+
+// LoadIndexFile takes a file at the given path and returns an IndexFile object
+func LoadIndexFile(c *swift.Connection, container string, path string) (*IndexFile, error) {
+       // TBD.tonyaw: didin't tested it
+       b, err := c.ObjectGetBytes(container, path)
+       if err != nil {
+               return nil, err
+       }
+       return loadIndex(b)
+}
+
+// tonyaw: return "IndexFile" defined in this file.
+func NewIndexFile() *IndexFile {
+       var indexFile *helm_repo.IndexFile
+
+       indexFile = &helm_repo.IndexFile{
+               APIVersion: helm_repo.APIVersionV1,
+               Generated:  time.Now(),
+               Entries:    map[string]helm_repo.ChartVersions{},
+               PublicKeys: []string{},
+       }
+
+       return &IndexFile{
+               IndexFile: indexFile,
+       }
+}
+
+// IndexFile represents the index file in a chart repository
+// tonyaw: here only add "WriteObject" function.
+type IndexFile struct {
+       *helm_repo.IndexFile
+}
+
+// WriteObject writes an index file to the given destination path.
+func (i IndexFile) WriteObject(c *swift.Connection, container, path string) error {
+       b, err := yaml.Marshal(i)
+       if err != nil {
+               return err
+       }
+
+       // tonyaw: if "index" exists, this step will overwrite it.
+       return c.ObjectPutBytes(container, path, b, "text/plain")
+}
+
+// tonyaw: Merge "IndexFile" defined in this file.
+func (i *IndexFile) Merge(f *IndexFile) {
+       for _, cvs := range f.Entries {
+               for _, cv := range cvs {
+                       if !i.Has(cv.Name, cv.Version) {
+                               e := i.Entries[cv.Name]
+                               i.Entries[cv.Name] = append(e, cv)
+                       }
+               }
+       }
+}
+
+// IndexDirectory reads a (flat) directory and generates an index.
+//
+// It indexes only charts that have been packaged (*.tgz).
+//
+// The index returned will be in an unsorted state
+func IndexDirectory(c *swift.Connection, container, baseURL, rootPath, indexName string) (*IndexFile, error) {
+       // tonyaw: Usw Swift command to replace FileSystem calls
+       objects, err := c.ObjectNames(container, nil)
+
+       if err != nil {
+               return nil, err
+       }
+       index := NewIndexFile()
+       for _, object := range objects {
+               if !strings.HasPrefix(object, rootPath) {
+                       continue
+               }
+               if object == filepath.Join(rootPath, indexName) {
+                       //log.Println("Ignore", filepath.Join(rootPath, indexName))
+                       continue
+               }
+               if !strings.HasSuffix(object, ".tgz") {
+                       log.Println("Ignore", object)
+                       continue
+               }
+
+               //fname := filepath.Base(object)
+               chartData, err := chartutil.Load(c, container, object)
+               if err != nil {
+                       log.Println("Error with object:", object, ",", err)
+                       continue
+               }
+               //huszty: open the object here for sha256 calculation
+               objectReader, _, err := c.ObjectOpen(container, object, false, nil)
+               //hash, err := provenance.DigestFile(object)
+               hash, err := provenance.Digest(objectReader)
+               if err != nil {
+                       return index, err
+               }
+               log.Println("Added:", object)
+               //huszty: index.Add would split the path from the object if url is provided
+               //so join the url with the prefixed object path to fake subdirectories correctly
+               objectPath, _ := urlutil.URLJoin(baseURL, object)
+               index.Add(chartData.Metadata, objectPath, "", hash)
+               objectReader.Close()
+       }
+       return index, nil
+}
+
+// loadIndex loads an index file and does minimal validity checking.
+//
+// This will fail if API Version is not set (ErrNoAPIVersion) or if the unmarshal fails.
+func loadIndex(data []byte) (*IndexFile, error) {
+       i := &IndexFile{}
+       if err := yaml.Unmarshal(data, i); err != nil {
+               return i, err
+       }
+
+       return i, nil
+}
+
+// tonyaw: refer to "index" from "helm/cmd/helm/repo_index.go".
+func Index(c *swift.Connection, container, url, rootPath, indexName string) error {
+       i, err := IndexDirectory(c, container, url, rootPath, indexName)
+       if err != nil {
+               return err
+       }
+       i.SortEntries()
+       return i.WriteObject(c, container, filepath.Join(rootPath, indexName))
+}