diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..7d4befa4a955189bb5d2e9765b4a1b03b2bd5c6e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,13 @@ +variables: + GC_GCR_REGISTRY: gcr.io/osdu-anthos + +include: + # Stages and standard settings + - local: "pipelines/stages.yml" + # Common scripts used in other jobs + - project: "osdu/platform/ci-cd-pipelines" + file: "cloud-providers/gc-scripts.yml" + # Helm logic + - local: "pipelines/helm-package.yml" + # Scripts check logic + - local: "pipelines/scripts_check.yml" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..261eeb9e9f8b2b4b0d119366dda99c6fd7d35c64 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + 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 + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/README.md b/README.md index 6d4d45bcd12f6645cc1cf94bbdbefca5f54a071c..d7eb5303286828b44df3bad5057044b212cb3034 100644 --- a/README.md +++ b/README.md @@ -1 +1,143 @@ -initial commit \ No newline at end of file +# Custom Metrics - Stackdriver Adapter + +Custom Metrics - Stackdriver Adapter is an implementation of [Custom Metrics +API] and [External Metrics API] using Stackdriver as a backend. Its purpose is +to enable pod autoscaling based on Stackdriver custom metrics. + +## Usage guide + +This guide shows how to set up Custom Metrics - Stackdriver Adapter and export +metrics to Stackdriver in a compatible way. Once this is done, you can use +them to scale your application, following [HPA walkthrough]. + +### Configure cluster + +1. Create Kubernetes cluster or use existing one, see [cluster setup]. + Requirements: + + * Kubernetes version 1.8.1 or newer running on GKE or GCE + + * Monitoring scope `monitoring` set up on cluster nodes. **It is enabled by + default, so you should not have to do anything**. See also [OAuth 2.0 API + Scopes] to learn more about authentication scopes. + + You can use following commands to verify that the scopes are set correctly: + * For GKE cluster `<my_cluster>`, use following command: + + ```sh + gcloud container clusters describe <my_cluster> + ``` + + For each node pool check the section `oauthScopes` - there should be + `https://www.googleapis.com/auth/monitoring` scope listed there. + * For a GCE instance `<my_instance>` use following command: + + ```sh + gcloud compute instances describe <my_instance> + ``` + + `https://www.googleapis.com/auth/monitoring` should be listed in the + `scopes` section. + + To configure set scopes manually, you can use: + * `--scopes` flag if you are using `gcloud container clusters create` + command, see [gcloud + documentation](https://cloud.google.com/sdk/gcloud/reference/container/clusters/create). + * Environment variable `NODE_SCOPES` if you are using [kube-up.sh script]. + It is enabled by default. + * To set scopes in existing clusters you can use `gcloud beta compute + instances set-scopes` command, see [gcloud + documentation](https://cloud.google.com/sdk/gcloud/reference/beta/compute/instances/set-scopes). + * On GKE, you need cluster-admin permissions on your cluster. You can grant + your user account these permissions with following command: + + ```sh + kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value account) + ``` + +1. Start *Custom Metrics - Stackdriver Adapter*. + +Stackdriver supports two models of Kubernetes resources: **the legacy model** +using monitored resource `gke_container` and **the new model** using different +Kubernetes monitored resources, including for example `k8s_pod`, `k8s_node`. See +[monitored resources documentation] for more details. + +* If you use **legacy resource model**: + + ```sh + kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter.yaml + ``` + +* If you use **new resource model**: + + ```sh + kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/k8s-stackdriver/master/custom-metrics-stackdriver-adapter/deploy/production/adapter_new_resource_model.yaml + ``` + +If you use Workload Identity in your cluster, additional steps are necessary. In +the commands below, use your Project ID as **`<project-id>`** and Google Service Account as +**`<google-service-account>`**. + +* Make sure your **`<google-service-account>`** has `monitoring.viewer` IAM role. + +* Create IAM Policy Binding: + + ```sh + gcloud iam service-accounts add-iam-policy-binding --role \ + roles/iam.workloadIdentityUser --member \ + "serviceAccount:<project-id>.svc.id.goog[custom-metrics/custom-metrics-stackdriver-adapter]" \ + <google-service-account>@<project-id>.iam.gserviceaccount.com + ``` + +* Annotate the Custom Metrics - Stackdriver Adapter service account: + + ```sh + kubectl annotate serviceaccount --namespace custom-metrics \ + custom-metrics-stackdriver-adapter \ + iam.gke.io/gcp-service-account=<google-service-account>@<project-id>.iam.gserviceaccount.com + ``` + +### Metrics available from Stackdriver + +Custom Metrics - Stackdriver Adapter exposes Stackdriver metrics to Kubernetes +components via two APIs. + +1. Any Stackdriver metric can be retrieved via **External Metrics API** with one + assumption: `metricType = DOUBLE` or `INT64`. For example, this API can be + used to configure Horizontal Pod Autoscaler to scale deployment based on any + of [existing metrics from other GCP services]. + +1. Metrics attached to Kubernetes objects, such as Pod or Node, can be retrieved + via **Custom Metrics API**. The following section provides more details about + exporting such metrics. + +#### Metric kinds + +Stackdriver specifies three metric kinds, all of which are supported by Custom +Metrics - Stackdriver Adapter: + +1. `GAUGE` - Each data point represents an instantaneous measurement, for + example the temperature. The adapter exposes the latest value. +1. `DELTA` - Each data point represents the change in a value over the time + interval. The adapter exposes *rate* of the metric - the metric change per + second computed over last 5 minutes. +1. `CUMULATIVE` - Each data point is a value being accumulated over time. The + adapter exposes *rate* of the metric - the metric change per second computed + over last 5 minutes. + +#### Metric names + +Stackdriver metrics have a form of pahths separated by "/" character, but Custom +Metrics API forbids using "/" character. When using Custom Metrics - Stackdriver +Adapter either directly via Custom Metrics API or by specifying a custom metric +in HPA, replace "/" character with "|". For example, to use +`custom.googleapis.com/my/custom/metric`, specify +`custom.googleapis.com|my|custom|metric`. + +#### Fallback for container metrics + +Flag `fallback-for-container-metrics` enables metrics from k8s_container, but in +limited scope. In particular, adapter will fallback to k8s_container resource +when given metric is not present on k8s_pod. +At most one container with given metric is allowed for each pod. +Works only with **new resource model**. diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d255a11894e549dd4a2cc87aa5d364096b9d15eb --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: custom-metrics +description: A Helm chart for custom metrics adapter + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "0.1.0" diff --git a/chart/templates/apiservice-external-metrics.yaml b/chart/templates/apiservice-external-metrics.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8b50cb71162b02f82a6259d59800adfbb0216cf3 --- /dev/null +++ b/chart/templates/apiservice-external-metrics.yaml @@ -0,0 +1,13 @@ +apiVersion: apiregistration.k8s.io/v1 +kind: APIService +metadata: + name: v1beta1.external.metrics.k8s.io +spec: + insecureSkipTLSVerify: true + group: external.metrics.k8s.io + groupPriorityMinimum: 100 + versionPriority: 100 + service: + name: custom-metrics-stackdriver-adapter + namespace: {{ .Values.global.saNamespace }} + version: v1beta1 diff --git a/chart/templates/apiservice-v1beta2.yaml b/chart/templates/apiservice-v1beta2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..da624e8ac9d976045568d89bb7b177d6cfb3a706 --- /dev/null +++ b/chart/templates/apiservice-v1beta2.yaml @@ -0,0 +1,13 @@ +apiVersion: apiregistration.k8s.io/v1 +kind: APIService +metadata: + name: v1beta2.custom.metrics.k8s.io +spec: + insecureSkipTLSVerify: true + group: custom.metrics.k8s.io + groupPriorityMinimum: 100 + versionPriority: 200 + service: + name: custom-metrics-stackdriver-adapter + namespace: {{ .Values.global.saNamespace }} + version: v1beta2 diff --git a/chart/templates/apiservice.yaml b/chart/templates/apiservice.yaml new file mode 100644 index 0000000000000000000000000000000000000000..46346b83f239a697728054627537139b4f4bc086 --- /dev/null +++ b/chart/templates/apiservice.yaml @@ -0,0 +1,13 @@ +apiVersion: apiregistration.k8s.io/v1 +kind: APIService +metadata: + name: v1beta1.custom.metrics.k8s.io +spec: + insecureSkipTLSVerify: true + group: custom.metrics.k8s.io + groupPriorityMinimum: {{ .Values.apiService.groupPriorityMinimum }} + versionPriority: {{ .Values.apiService.versionPriority }} + service: + name: custom-metrics-stackdriver-adapter + namespace: {{ .Values.global.saNamespace }} + version: v1beta1 diff --git a/chart/templates/clusterrole.yaml b/chart/templates/clusterrole.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b94199a7df05b642b3faf1b73b605213d295ff03 --- /dev/null +++ b/chart/templates/clusterrole.yaml @@ -0,0 +1,8 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: custom-metrics-resource-reader +rules: + - apiGroups: [""] + resources: ["pods", "nodes", "nodes/stats"] + verbs: ["get", "list", "watch"] diff --git a/chart/templates/clusterrolebinding-auth-delegator.yaml b/chart/templates/clusterrolebinding-auth-delegator.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9ba2142cd29b888c0d4da4b0b1a214eb67a45a4d --- /dev/null +++ b/chart/templates/clusterrolebinding-auth-delegator.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: custom-metrics:system:auth-delegator +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: system:auth-delegator +subjects: +- kind: ServiceAccount + name: {{ .Values.serviceAccount.name }} + namespace: {{ .Values.global.saNamespace }} diff --git a/chart/templates/clusterrolebinding-external-metrics.yaml b/chart/templates/clusterrolebinding-external-metrics.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4f662483692d7c726508e0d35819ac04c3613daa --- /dev/null +++ b/chart/templates/clusterrolebinding-external-metrics.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: external-metrics-reader +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: external-metrics-reader +subjects: +- kind: ServiceAccount + name: horizontal-pod-autoscaler + namespace: kube-system diff --git a/chart/templates/clusterrolebinding-resource-reader.yaml b/chart/templates/clusterrolebinding-resource-reader.yaml new file mode 100644 index 0000000000000000000000000000000000000000..aad742162040a778367474445732dbe5f17db1a3 --- /dev/null +++ b/chart/templates/clusterrolebinding-resource-reader.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: custom-metrics-resource-reader +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: custom-metrics-resource-reader +subjects: +- kind: ServiceAccount + name: {{ .Values.serviceAccount.name }} + namespace: {{ .Values.global.saNamespace }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 0000000000000000000000000000000000000000..372ab228a2260cb7fdd7fbc4b0faec9381a36d39 --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: custom-metrics-stackdriver-adapter + namespace: {{ .Values.global.saNamespace }} + labels: + run: custom-metrics-stackdriver-adapter + k8s-app: custom-metrics-stackdriver-adapter +spec: + replicas: {{ .Values.deployment.replicas }} + selector: + matchLabels: + run: custom-metrics-stackdriver-adapter + k8s-app: custom-metrics-stackdriver-adapter + template: + metadata: + labels: + run: custom-metrics-stackdriver-adapter + k8s-app: custom-metrics-stackdriver-adapter + spec: + serviceAccountName: {{ .Values.serviceAccount.name }} + containers: + - image: {{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }} + name: pod-custom-metrics-stackdriver-adapter + resources: + limits: + cpu: {{ .Values.deployment.resources.limits.cpu }} + memory: {{ .Values.deployment.resources.limits.memory }} + requests: + cpu: {{ .Values.deployment.resources.requests.cpu }} + memory: {{ .Values.deployment.resources.requests.memory }} + command: + - /adapter + - --use-new-resource-model=true + - --fallback-for-container-metrics=true diff --git a/chart/templates/rolebinding.yaml b/chart/templates/rolebinding.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e6eeee6492820445337e12234aa48eeea7106bdc --- /dev/null +++ b/chart/templates/rolebinding.yaml @@ -0,0 +1,13 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: custom-metrics-auth-reader + namespace: kube-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: extension-apiserver-authentication-reader +subjects: +- kind: ServiceAccount + name: {{ .Values.serviceAccount.name }} + namespace: {{ .Values.global.saNamespace }} diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6bf68ab20822faaffc72b6c57e8b02315c540e50 --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + run: custom-metrics-stackdriver-adapter + k8s-app: custom-metrics-stackdriver-adapter + kubernetes.io/cluster-service: 'true' + kubernetes.io/name: Adapter + name: custom-metrics-stackdriver-adapter + namespace: {{ .Values.global.saNamespace }} +spec: + ports: + - port: {{ .Values.service.port }} + protocol: TCP + targetPort: {{ .Values.service.targetPort }} + selector: + run: custom-metrics-stackdriver-adapter + k8s-app: custom-metrics-stackdriver-adapter + type: ClusterIP diff --git a/chart/templates/serviceaccount.yaml b/chart/templates/serviceaccount.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6f850f23bd673765478ab535a80a31a5d464123c --- /dev/null +++ b/chart/templates/serviceaccount.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + annotations: + iam.gke.io/gcp-service-account: "wi-{{ .Values.serviceAccount.name }}-gc@{{ .Values.global.projectId }}.iam.gserviceaccount.com" + name: {{ .Values.serviceAccount.name | quote }} + namespace: {{ .Values.global.saNamespace }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3c3c957d864d61770be4851d63c83d54ec2bc3bb --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,27 @@ +global: + projectId: "" + saNamespace: "custom-metrics" + +serviceAccount: + name: adapter + +deployment: + replicas: 1 + image: + repository: gcr.io/gke-release/custom-metrics-stackdriver-adapter + tag: v0.15.1-gke.0 + resources: + requests: + cpu: 250m + memory: 200Mi + limits: + cpu: 250m + memory: 200Mi + +service: + port: 443 + targetPort: 443 + +apiService: + groupPriorityMinimum: 100 + versionPriority: 100 diff --git a/pipelines/helm-package.yml b/pipelines/helm-package.yml new file mode 100644 index 0000000000000000000000000000000000000000..c6463cd7aee8cfa95a75c5b0e4ce277d308eef8f --- /dev/null +++ b/pipelines/helm-package.yml @@ -0,0 +1,67 @@ +variables: + GC_HELM_DEPLOYMENT_DIR: "chart" + GC_HELM_PACKAGE_NAME: "custom-metrics" + GC_GCR_REGISTRY: "gcr.io/osdu-anthos" + +.gc_get_latest_helm_package_version: + script: + - wget -q https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq + +gc-helm-charts-gitlab: + stage: package + tags: ["osdu-small"] + image: + name: alpine/helm:3.11.2 + entrypoint: [""] + rules: + - if: "$CI_COMMIT_TAG" + when: never + - if: "$CI_PIPELINE_SOURCE == 'merge_request_event'" + when: on_success + - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH" + when: on_success + before_script: + - helm registry login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - !reference [.gc_set_image_name, script] + - !reference [.gc_get_latest_helm_package_version, script] + script: + - helm package $GC_HELM_DEPLOYMENT_DIR -u --version $GC_HELM_PACKAGE_VERSION-$HELM_TAG + - helm push $GC_HELM_PACKAGE_NAME-$GC_HELM_PACKAGE_VERSION-$HELM_TAG.tgz oci://$CI_REGISTRY_IMAGE/gc-helm + +gc-helm-charts-release-gitlab: + stage: package + tags: ["osdu-small"] + image: + name: alpine/helm:3.11.2 + entrypoint: [""] + rules: + - if: '$GC == "1" && $CI_COMMIT_TAG' + when: on_success + before_script: + - helm registry login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - !reference [.gc_set_image_name, script] + script: + - !reference [.gc_define_version, script] + - helm package $GC_HELM_DEPLOYMENT_DIR -u --version $VERSION + - helm push $GC_HELM_PACKAGE_NAME-$VERSION.tgz oci://$CI_REGISTRY_IMAGE/gc-helm + +gc-helm-charts-release-gcr: + environment: + name: Google_Cloud + stage: package + tags: ["osdu-small"] + image: + name: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine + entrypoint: [""] + rules: + - if: '$GC == "1" && $CI_COMMIT_TAG' + when: on_success + before_script: + - apk add --no-cache curl bash + - curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | VERIFY_CHECKSUM=false bash + - gcloud auth activate-service-account --key-file=${GC_BAREMETAL_DEPLOY_FILE} + - gcloud auth configure-docker gcr.io + script: + - !reference [.gc_define_version, script] + - helm package $GC_HELM_DEPLOYMENT_DIR -u --version $VERSION + - helm push $GC_HELM_PACKAGE_NAME-$VERSION.tgz oci://$GC_GCR_REGISTRY/helm diff --git a/pipelines/scripts_check.yml b/pipelines/scripts_check.yml new file mode 100644 index 0000000000000000000000000000000000000000..fbb0e7f4bde0de82be90ca99c135abd069f4b6c6 --- /dev/null +++ b/pipelines/scripts_check.yml @@ -0,0 +1,32 @@ +.linter-check: + tags: ["osdu-small"] + stage: scripts_check + rules: + - if: '$CI_PIPELINE_SOURCE != "schedule"' + when: on_success + +md_structure-check: + extends: .linter-check + image: node:alpine + script: + - npm install -g markdownlint-cli + - markdownlint --disable MD013 MD033 -- . + +helm_check: + extends: .linter-check + stage: scripts_check + image: + name: alpine/helm:3.11.2 + entrypoint: [""] + before_script: + - wget https://github.com/instrumenta/kubeval/releases/download/v0.16.1/kubeval-linux-amd64.tar.gz + - tar xf kubeval-linux-amd64.tar.gz + - cp kubeval /usr/local/bin + script: + - helm lint chart/ + - cd chart + - > + helm template lint-test . + --set global.projectId="test-project" + > template.yaml + - kubeval --ignore-missing-schemas template.yaml diff --git a/pipelines/stages.yml b/pipelines/stages.yml new file mode 100644 index 0000000000000000000000000000000000000000..c16be3c6309135d822d57d5166c4d2941bf607bd --- /dev/null +++ b/pipelines/stages.yml @@ -0,0 +1,3 @@ +stages: + - scripts_check + - package