Add Atomix primitives to fabric adapter

Change-Id: I171c586a04fcb0586969d06b8336e0c98018cdce
diff --git a/fabric-adapter/Chart.yaml b/fabric-adapter/Chart.yaml
index 72580b7..eb1fa5e 100644
--- a/fabric-adapter/Chart.yaml
+++ b/fabric-adapter/Chart.yaml
@@ -7,7 +7,7 @@
 name: fabric-adapter
 kubeVersion: ">=1.17.0"
 type: application
-version: 0.1.1
+version: 0.1.2
 appVersion: v0.0.4
 description: Aether Fabric Adapter
 keywords:
diff --git a/fabric-adapter/templates/_helpers.tpl b/fabric-adapter/templates/_helpers.tpl
index 7878594..ef34f5a 100644
--- a/fabric-adapter/templates/_helpers.tpl
+++ b/fabric-adapter/templates/_helpers.tpl
@@ -55,3 +55,35 @@
 app.kubernetes.io/name: {{ include "fabric-adapter.name" . }}
 app.kubernetes.io/instance: {{ .Release.Name }}
 {{- end -}}
+
+{{/*
+fabric-adapter consensus image name
+*/}}
+{{- define "fabric-adapter.store.consensus.imagename" -}}
+{{- if or .Values.store.consensus.image.tag .Values.global.store.consensus.image.tag -}}
+{{- if .Values.global.store.consensus.image.registry -}}
+{{- printf "%s/" .Values.global.store.consensus.image.registry -}}
+{{- else if .Values.store.consensus.image.registry -}}
+{{- printf "%s/" .Values.store.consensus.image.registry -}}
+{{- end -}}
+{{- printf "%s:" .Values.store.consensus.image.repository -}}
+{{- if .Values.global.store.consensus.image.tag -}}
+{{- .Values.global.store.consensus.image.tag -}}
+{{- else -}}
+{{- .Values.store.consensus.image.tag -}}
+{{- end -}}
+{{- else -}}
+""
+{{- end -}}
+{{- end -}}
+
+{{/*
+fabric-adapter consensus store name
+*/}}
+{{- define "fabric-adapter.store.consensus.name" -}}
+{{- if .Values.store.consensus.name -}}
+{{- printf "%s" .Values.store.consensus.name -}}
+{{- else -}}
+{{- printf "%s-consensus-store" ( include "fabric-adapter.fullname" . ) -}}
+{{- end -}}
+{{- end -}}
diff --git a/fabric-adapter/templates/deployment.yaml b/fabric-adapter/templates/deployment.yaml
index e9e726b..b05418e 100644
--- a/fabric-adapter/templates/deployment.yaml
+++ b/fabric-adapter/templates/deployment.yaml
@@ -20,11 +20,15 @@
       labels:
         name: {{ template "fabric-adapter.fullname" . }}
         {{- include "fabric-adapter.selectorLabels" . | nindent 8 }}
+      annotations:
+        broker.atomix.io/inject: "true"
+        raft.storage.atomix.io/inject: "true"
     spec:
     {{- with .Values.imagePullSecrets }}
       imagePullSecrets:
         {{- toYaml . | nindent 6 }}
     {{- end }}
+      serviceAccountName: {{ template "fabric-adapter.fullname" . }}
       securityContext:
         {{- toYaml .Values.podSecurityContext | nindent 8 }}
       containers:
@@ -90,3 +94,6 @@
         - name: secret
           secret:
             secretName: {{ template "fabric-adapter.fullname" . }}-secret
+        - name: config
+          configMap:
+            name: {{ template "fabric-adapter.fullname" . }}-config
diff --git a/fabric-adapter/templates/primitives.yaml b/fabric-adapter/templates/primitives.yaml
new file mode 100644
index 0000000..d89fc1e
--- /dev/null
+++ b/fabric-adapter/templates/primitives.yaml
@@ -0,0 +1,30 @@
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+apiVersion: primitives.atomix.io/v2beta1
+kind: Counter
+metadata:
+  name: fabric-adapter-sid-counter
+  namespace: {{ .Release.Namespace }}
+spec:
+  store:
+    {{- if .Values.global.store.consensus.enabled }}
+    name: {{ template "global.store.consensus.name" . }}
+    {{- else }}
+    name: {{ template "fabric-adapter.store.consensus.name" . }}
+    {{- end }}
+---
+apiVersion: primitives.atomix.io/v2beta1
+kind: Map
+metadata:
+  name: fabric-adapter-sid-map
+  namespace: {{ .Release.Namespace }}
+spec:
+  store:
+    {{- if .Values.global.store.consensus.enabled }}
+    name: {{ template "global.store.consensus.name" . }}
+    {{- else }}
+    name: {{ template "fabric-adapter.store.consensus.name" . }}
+    {{- end }}
+---
\ No newline at end of file
diff --git a/fabric-adapter/templates/role.yaml b/fabric-adapter/templates/role.yaml
new file mode 100644
index 0000000..4e04428
--- /dev/null
+++ b/fabric-adapter/templates/role.yaml
@@ -0,0 +1,21 @@
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
+  creationTimestamp: null
+  name: {{ template "fabric-adapter.fullname" . }}
+  namespace: {{ .Release.Namespace }}
+rules:
+  - apiGroups:
+      - primitives.atomix.io
+    resources:
+      - '*'
+    resourceNames:
+      - fabric-adapter-sid-counter
+      - fabric-adapter-sid-map
+
+    verbs:
+      - '*'
\ No newline at end of file
diff --git a/fabric-adapter/templates/rolebinding.yaml b/fabric-adapter/templates/rolebinding.yaml
new file mode 100644
index 0000000..a2d922a
--- /dev/null
+++ b/fabric-adapter/templates/rolebinding.yaml
@@ -0,0 +1,16 @@
+# SPDX-FileCopyrightText: 2022 2020-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: Apache-2.0
+
+kind: RoleBinding
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: {{ template "fabric-adapter.fullname" . }}
+  namespace: {{ .Release.Namespace }}
+subjects:
+- kind: ServiceAccount
+  name: {{ template "fabric-adapter.fullname" . }}
+roleRef:
+  kind: Role
+  name: {{ template "fabric-adapter.fullname" . }}
+  apiGroup: rbac.authorization.k8s.io
\ No newline at end of file
diff --git a/fabric-adapter/templates/serviceaccount.yaml b/fabric-adapter/templates/serviceaccount.yaml
new file mode 100644
index 0000000..e17f846
--- /dev/null
+++ b/fabric-adapter/templates/serviceaccount.yaml
@@ -0,0 +1,9 @@
+# SPDX-FileCopyrightText: 2022 2020-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: Apache-2.0
+
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: {{ template "fabric-adapter.fullname" . }}
+  namespace: {{ .Release.Namespace }}
\ No newline at end of file
diff --git a/fabric-adapter/templates/store.yaml b/fabric-adapter/templates/store.yaml
new file mode 100644
index 0000000..70e1b4d
--- /dev/null
+++ b/fabric-adapter/templates/store.yaml
@@ -0,0 +1,42 @@
+# SPDX-FileCopyrightText: 2022 2020-present Open Networking Foundation <info@opennetworking.org>
+#
+# SPDX-License-Identifier: Apache-2.0
+
+{{- if .Values.store.consensus.enabled }}
+apiVersion: atomix.io/v2beta1
+kind: Store
+metadata:
+  name: {{ template "fabric-adapter.store.consensus.name" . }}
+  namespace: {{ .Release.Namespace }}
+spec:
+  protocol:
+    apiVersion: storage.atomix.io/v2beta2
+    kind: MultiRaftProtocol
+    spec:
+      replicas: {{ .Values.store.consensus.replicas }}
+      groups: {{ .Values.store.consensus.partitions }}
+      {{- with .Values.store.consensus.raft }}
+      raft:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      image: {{ template "fabric-adapter.store.consensus.imagename" . }}
+      imagePullPolicy: {{ .Values.store.consensus.image.pullPolicy }}
+      {{- with .Values.store.consensus.image.pullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- with .Values.store.consensus.securityContext }}
+      securityContext:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      {{- if .Values.store.consensus.persistence.storageClass }}
+      volumeClaimTemplate:
+        spec:
+          accessModes:
+          - ReadWriteOnce
+          storageClassName: {{ .Values.store.consensus.persistence.storageClass | quote }}
+          resources:
+            requests:
+              storage: {{ .Values.store.consensus.persistence.storageSize }}
+      {{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/fabric-adapter/values.yaml b/fabric-adapter/values.yaml
index 5e12cb3..971cc25 100644
--- a/fabric-adapter/values.yaml
+++ b/fabric-adapter/values.yaml
@@ -3,6 +3,14 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 
+global:
+  store:
+    consensus:
+      name: ""
+      image:
+        registry: ""
+        tag: ""
+
 nameOverride: ""
 fullnameOverride: ""
 
@@ -53,3 +61,21 @@
     stdout:
       type: stdout
       stdout: {}
+
+store:
+  consensus:
+    enabled: true
+    name: ""
+    image:
+      registry: ""
+      repository: atomix/atomix-raft-storage-node
+      tag: ""
+      pullPolicy: IfNotPresent
+      pullSecrets: []
+    clusters: 1
+    replicas: 1
+    partitions: 1
+    raft: {}
+    persistence:
+      storageClass: ""
+      storageSize: 1Gi
diff --git a/fabric-umbrella/Chart.yaml b/fabric-umbrella/Chart.yaml
index 56cdf92..92ae90a 100644
--- a/fabric-umbrella/Chart.yaml
+++ b/fabric-umbrella/Chart.yaml
@@ -7,7 +7,7 @@
 description: Fabric ROC Umbrella chart to deploy all Fabric ROC
 kubeVersion: ">=1.18.0"
 type: application
-version: 0.1.12
+version: 0.1.13
 appVersion: v0.0.0
 keywords:
   - aether
@@ -42,7 +42,7 @@
   - name: fabric-adapter
     condition: import.fabric-adapter.v0-1.enabled
     repository: "file://../fabric-adapter"
-    version: 0.1.1
+    version: 0.1.2
     alias: fabric-adapter-v0-1
   - name: nginx
     alias: fabric-test-dummy