Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Helmchart for groups-service #165

Open
wants to merge 4 commits into
base: helm-chart
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ public interface Constants {
public static final String OBJECT_TYPE = "objectType";
public static final String INSERT = "insert";
public static final String STANDALONE_MODE = "standalone";
public static final String IS_MULTI_DC_ENABLED = "isMultiDCEnabled";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sunbird.helper;

import com.datastax.driver.core.*;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.DefaultRetryPolicy;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -66,7 +67,8 @@ private void createCassandraConnection(String[] hosts) throws BaseException {
poolingOptions.setPoolTimeoutMillis(
Integer.parseInt(cache.getProperty(Constants.POOL_TIMEOUT)));

cluster = createCluster(hosts, poolingOptions);
//check for multi DC enabled or not from configuration file and send the value
cluster = createCluster(hosts, poolingOptions, Boolean.parseBoolean(cache.getProperty(Constants.IS_MULTI_DC_ENABLED)));

final Metadata metadata = cluster.getMetadata();
String msg = String.format("Connected to cluster: %s", metadata.getClusterName());
Expand All @@ -86,7 +88,7 @@ private void createCassandraConnection(String[] hosts) throws BaseException {
}
}

private static Cluster createCluster(String[] hosts, PoolingOptions poolingOptions) {
private static Cluster createCluster(String[] hosts, PoolingOptions poolingOptions, boolean isMultiDCEnabled) {
Cluster.Builder builder =
Cluster.builder()
.addContactPoints(hosts)
Expand All @@ -103,6 +105,12 @@ private static Cluster createCluster(String[] hosts, PoolingOptions poolingOptio
builder.withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel));
}

logger.info(
"CassandraConnectionManagerImpl:createCluster: isMultiDCEnabled = " + isMultiDCEnabled);
if (isMultiDCEnabled) {
builder.withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().build());
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ port=9042
userName=cassandra
password=password
queryLoggerConstantThreshold=300
keyspace=sunbird
keyspace=sunbird
isMultiDCEnabled=true
23 changes: 23 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions helm/groups/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: sb-groups-service
description: A Helm chart for Sunbird Lern group service

# 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: "5.0.0"
23 changes: 23 additions & 0 deletions helm/groups/charts/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions helm/groups/charts/common/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions helm/groups/charts/common/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: common
description: A helm chart for common templates

# 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: library

# 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: "5.0.0"
3 changes: 3 additions & 0 deletions helm/groups/charts/common/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "common.read.configmap.name" -}}
{{- printf "%s-config" .Chart.Name -}}
{{- end -}}
3 changes: 3 additions & 0 deletions helm/groups/charts/common/templates/_randomize.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "common.randomize" }}
{{- randAlphaNum . | trim }}
{{- end }}
40 changes: 40 additions & 0 deletions helm/groups/charts/common/templates/_readsecret.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- define "common.read.secret" -}}
{{- $secret := (lookup "v1" "Secret" .Namespace .Name).data -}}
{{- if $secret -}}
{{- if hasKey $secret .Key -}}
{{- index $secret .Key | b64dec -}}
{{- else -}}
{{- if .LocalDevelopment -}}
{{- printf "Ignoring API server errors to allow templating" -}}
{{- else -}}
{{- printf "ERROR | %s | The secret \"%s\" does not contain the key \"%s\" in namespace \"%s\"" .ChartName .Name .Key .Namespace | fail -}}
{{- end -}}
{{- end -}}
{{ else -}}
{{- if .LocalDevelopment -}}
{{- printf "Ignoring API server errors to allow templating" -}}
{{- else -}}
{{- printf "ERROR | %s | The secret \"%s\" does not exist in the namespace \"%s\"" .ChartName .Name .Namespace | fail -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "common.secret.exists" -}}
{{ $secret := (lookup "v1" "Secret" .Namespace .Name).data}}
{{- if $secret -}}
{{- if hasKey $secret .Key -}}
{{- true -}}
{{- else -}}
{{- false -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "common.secret.as.map" -}}
{{ $secret := (lookup "v1" "Secret" .Namespace .Name).data}}
{{- if $secret -}}
{{- $secret -}}
{{- else -}}
{{- false -}}
{{- end -}}
{{- end -}}
9 changes: 9 additions & 0 deletions helm/groups/charts/common/templates/_valdations.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- define "common.valid.csps" -}}
{{- $validcsps := "azure or aws or gcloud" -}}
{{- printf "%s" $validcsps -}}
{{- end -}}

{{- define "common.csp.validation" -}}
{{- $csplist := list "azure" "aws" "gcloud" -}}
{{- has . $csplist -}}
{{- end -}}
1 change: 1 addition & 0 deletions helm/groups/charts/common/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## Common helm templates
16 changes: 16 additions & 0 deletions helm/groups/groups-sample-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## This section has mandatory variables
## You must provide a value for these
## If you don't provide a value for these variables, the chart installation will not proceed

## The domain name or Public IP address
## The domain name should start with http or https
## For example https://example.com
domain: "https://abc.com"

## This section has optional variables
## It is strongly recommended to provide a value for these
## If you don't provide a value for these variables, they will default to empty values
## If these variables are empty, some features on the application might not work as expected



62 changes: 62 additions & 0 deletions helm/groups/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "sb-groups-service.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sb-groups-service.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sb-groups-service.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "sb-groups-service.labels" -}}
helm.sh/chart: {{ include "sb-groups-service.chart" . }}
{{ include "sb-groups-service.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "sb-groups-service.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sb-groups-service.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "sb-groups-service.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "sb-groups-service.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
65 changes: 65 additions & 0 deletions helm/groups/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Chart.Name }}-config
namespace: {{ .Release.Namespace }}
data:
{{/* This section has variables whose value is read from another object */}}

{{/* This section has variables which in turn contain one or more mandatory variables */}}
sunbird_sso_url: {{ if .Values.domain }}
{{- .Values.domain }}{{ .Values.keycloak_auth_endpoint }}
{{- else -}}
{{- printf "ERROR | %s | Please provide a value for \"domain\"" .Chart.Name | fail }}
{{- end }}

sunbird_keycloak_user_federation_provider_id: {{ if .Values.sunbird_keycloak_user_federation_provider_id }}
{{- .Values.sunbird_keycloak_user_federation_provider_id }}
{{- else -}}
{{- include "common.read.secret" (dict "ChartName" .Chart.Name "Namespace" .Release.Namespace "Name" .Values.external_secrets.keycloak_federation.name "Key" .Values.external_secrets.keycloak_federation.key "LocalDevelopment" .Values.local_chart_development) -}}
{{- end }}

sunbird_sso_client_secret: {{ if .Values.sunbird_sso_client_secret }}
{{- .Values.sunbird_sso_client_secret }}
{{- else -}}
{{- include "common.read.secret" (dict "ChartName" .Chart.Name "Namespace" .Release.Namespace "Name" .Values.external_secrets.keycloak_client_secret.name "Key" .Values.external_secrets.keycloak_client_secret.key "LocalDevelopment" .Values.local_chart_development) -}}
{{- end }}

sunbird_sso_publickey: {{ if .Values.sunbird_sso_publickey }}
{{- .Values.sunbird_sso_publickey }}
{{- else -}}
{{- include "common.read.secret" (dict "ChartName" .Chart.Name "Namespace" .Release.Namespace "Name" .Values.external_secrets.keycloak_realm_public_key.name "Key" .Values.external_secrets.keycloak_realm_public_key.key "LocalDevelopment" .Values.local_chart_development) -}}
{{- end }}
{{/* This section has optional variables */}}

{{/* This section has variables with default values */}}
CONTENT_SERVICE_PORT: {{ .Values.CONTENT_SERVICE_PORT }}
ENV_NAME: {{ .Values.ENV_NAME }}
LEARNER_SERVICE_PORT: {{ .Values.LEARNER_SERVICE_PORT }}
SUNBIRD_KAFKA_URL: {{ .Values.SUNBIRD_KAFKA_URL }}
accesstoken.publickey.basepath: {{ .Values.accesstoken.publickey.basepath }}
enable_tenant_config: {{ .Values.enable_tenant_config | quote}}
enable_userid_redis_cache: {{ .Values.enable_userid_redis_cache | quote }}
groups_redis_ttl: {{ .Values.groups_redis_ttl }}
isMultiDCEnabled: {{ .Values.isMultiDCEnabled | quote }}
max_activity_limit: {{ .Values.max_activity_limit}}
max_group_limit: {{ .Values.max_group_limit }}
max_group_members_limit: {{ .Values.max_group_members_limit }}
notification_service_api_url: {{ .Values.notification_service_api_url }}
notification_service_base_url: {{ .Values.notification_service_base_url }}
sunbird_cassandra_consistency_level: {{ .Values.sunbird_cassandra_consistency_level }}
sunbird_cassandra_host: {{ .Values.sunbird_cassandra_host }}
sunbird_cassandra_password: {{ .Values.sunbird_cassandra_password }}
sunbird_cassandra_port: {{ .Values.sunbird_cassandra_port | quote }}
sunbird_cassandra_username: {{ .Values.sunbird_cassandra_username }}
sunbird_cs_search_url: "/v3/search"
sunbird_keycloak_required_action_link_expiration_seconds: {{ .Values.sunbird_keycloak_required_action_link_expiration_seconds | quote }}
sunbird_redis_host: {{ .Values.sunbird_redis_host }}
sunbird_redis_port: {{ .Values.sunbird_redis_port | quote }}
sunbird_sso_client_id: {{ .Values.external_secrets.keycloak_client_secret.key }}
sunbird_sso_password: {{ .Values.sunbird_sso_password }}
sunbird_sso_realm: {{ .Values.external_secrets.keycloak_realm_public_key.key }}
sunbird_sso_username: {{ .Values.sunbird_sso_username }}
sunbird_user_service_search_url: {{ .Values.sunbird_user_service_search_url }}
user_redis_ttl: {{ .Values.user_redis_ttl }}
Loading