amitkumardas / decide Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
The use of CAS Templates in openebs control plane enables defining operations via yaml i.e. declarative approach. The main motive is to make faster releases without having to go through code compilation & related dependencies. The other equally important motive is to enable openebs easier for community & user contribution. In other words make openebs contributions decentralised.
In light of above goods, it becomes imperative to make this declarative approach simpler to understand, use, execute, rollback & debug in case of failures. Below is a high level approach (read v1beta1
version) to ensure true effectiveness of CAS Templates.
metadata:
name: DoItTask
spec:
id: MyCoolRT
# list of yamls
yamls:
- id: svcYaml
content: |
apiVersion: v1
kind: Service
metadata:
labels:
openebs.io/controller-service: jiva-controller-svc
openebs.io/storage-engine-type: jiva
openebs.io/pv: {{ .Volume.owner }}
name: {{ .Volume.owner }}-ctrl-svc
spec:
ports:
- name: iscsi
port: 3260
protocol: TCP
targetPort: 3260
- name: api
port: 9501
protocol: TCP
targetPort: 9501
selector:
openebs.io/controller: jiva-controller
openebs.io/pv: {{ .Volume.owner }}
# list of executions
executions:
- >
{{/*
Create a service based on provided yaml and store its ip and name
*/}}
{{- kubectl "MyPutSvc" |
yaml .MyCoolRT.svcYaml |
put "svc" |
jsonpath "{range .items[*]}ip={@.spec.clusterIP},name={@.metadata.name};{end}" |
itemSplit ";" |
pairSplit ", =" |
pick "ip" "MyCoolRT.MyPutSvc.ip" |
pick "name" "MyCoolRT.MyPutSvc.name" |
build -}}
- >
{{/*
Get service based on name and store its cluster ip
*/}}
{{- kubectl "MyGetSvc" |
get "svc" |
name .Volume.owner |
ns .Volume.runNamespace |
jsonpath "{.spec.clusterIP}" |
labelSelector .Volume.options |
set "MyCoolRT.MyGetSvc.clusterIP" |
build -}}
- >
{{/*
List services based on selector and store each service's ip and name
*/}}
{{- kubectl "MyListSvc" |
list "svc" |
labelSelector .Volume.options |
jsonpath "{range .items[*]}ip={@.spec.clusterIP},name={@.metadata.name};{end}" |
itemSplit ";" |
pairSplit ", =" |
pick "ip" "MyCoolRT.MyListSvc.ip" |
pick "name" "MyCoolRT.MyListSvc.name" |
build -}}
rollbacks:
- blah blah
- blah blah
go struct
:method chaining
pkg/apis/v1/doc.go
doc_values.go
,run_task_specs.go
,label.go
,field.go
,select.go
,query.go
,cas_template_specs.go
pkg/engine/v1/cas_template_engine.go
pkg/task/v1/run_task.go
pkg/template/v1/task_templates.go
type eventHandle interface {
eventHookTypeA
eventHookTypeB
// DON'T add TypeC interface.
someOtherMethod() results
}
type eventHookTypeA interface {
// method definitions
HandleEventA() results
}
type eventHookTypeB interface {
// method definitions
HandleEventB() results
}
type eventHookTypeC interface {
HandleEventC() results
}
func handleEvents(eventType string, handle eventHandle) results {
if eventType == "eventA" {
return handle.HandleEventA()
} else if eventType == "eventB" {
return handle.HandleEventB()
} else if eventType == "eventC" {
if c,ok := handle.(eventHookTypeC); ok {
return c.HandleEventC()
} else {
log.Println("somewhat bad happen")
}
}
return nil
}
ref: https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/crds/crds.go
import (
"encoding/json"
"github.com/ghodss/yaml"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kube-openapi/pkg/common"
)
package crds
// Annotation is to mark a field as annotations.
// "x-kubernetes-annotation": ""
const Annotation = "x-kubernetes-annotation"
// LabelSelector is to mark a field as LabelSelector
// "x-kubernetes-label-selector": ""
const LabelSelector = "x-kubernetes-label-selector"
// Identity is to mark a field as Identity
// "x-kubernetes-identity": ""
const Identity = "x-kubernetes-identity"
// Version marks the type version of an object ref field
// "x-kubernetes-object-ref-api-version": <apiVersion name>
const Version = "x-kubernetes-object-ref-api-version"
// Kind marks the type name of an object ref field
// "x-kubernetes-object-ref-kind": <kind name>
const Kind = "x-kubernetes-object-ref-kind"
// NameKey marks the field key that refers to an object of an object ref field
// "x-kubernetes-object-ref-name-key": "name"
// default is "name"
const NameKey = "x-kubernetes-object-ref-name-key"
var types map[string]common.OpenAPIDefinition
if content[0] == '{' {
err = json.Unmarshal(content, &types)
if err != nil {
return nil, err
}
} else {
err = yaml.Unmarshal(content, &types)
if err != nil {
return nil, err
}
}
// getCRDs get all CRD types
func getCRDs(types map[string]common.OpenAPIDefinition) map[string]schema.GroupVersionKind
{
crds := map[string]schema.GroupVersionKind{}
for typename, t := range types {
properties := t.Schema.SchemaProps.Properties
_, foundKind := properties["kind"]
_, foundAPIVersion := properties["apiVersion"]
_, foundMetadata := properties["metadata"]
if foundKind && foundAPIVersion && foundMetadata {
// TODO: Get Group and Version for CRD from the openAPI definition once
// "x-kubernetes-group-version-kind" is available in CRD
kind := strings.Split(typename, ".")[len(strings.Split(typename, "."))-1]
crds[typename] = schema.GroupVersionKind{Kind: kind}
}
}
return crds
}
types map[string]common.OpenAPIDefinition
for propname, property := range types[atype].Schema.SchemaProps.Properties {
_, annotate := property.Extensions.GetString(Annotation)
if annotate {...}
_, label := property.Extensions.GetString(LabelSelector)
if label {...}
_, identity := property.Extensions.GetString(Identity)
if identity {...}
version, ok := property.Extensions.GetString(Version)
if ok {
kind, ok := property.Extensions.GetString(Kind)
if ok {
nameKey, ok := property.Extensions.GetString(NameKey)
if !ok {...}
}
}
if property.Ref.GetURL() != nil {...}
}
spec:
defaultConfig:
- name: VolumeMonitor
enabled: "true"
- name: ControllerImage
value: openebs/jiva:0.5.0
- name: ReplicaImage
value: openebs/jiva:0.5.0
- name: ReplicaCount
value: "1"
- name: StoragePool
value: jiva-pool-path-default-0.7.0
- name: TaintTolerations
value: |-
t1:
key: node.openebs.io/disktype
operator: Equal
value: ssd
effect: NoSchedule
t2:
key: node.openebs.io/disktype
operator: Equal
value: ssd
effect: NoExecute
- name: EvictionTolerations
value: |-
t1:
effect: NoExecute
key: node.alpha.kubernetes.io/notReady
operator: Exists
t2:
effect: NoExecute
key: node.alpha.kubernetes.io/unreachable
operator: Exists
- name: NodeAffinityRequiredSchedIgnoredExec
value: |-
t1:
key: beta.kubernetes.io/os
operator: In
values:
- linux
- name: NodeAffinityPreferredSchedIgnoredExec
value: |-
t1:
key: some-node-label-key
operator: In
values:
- some-node-label-value
{{- $isTaintTolerations := .Config.TaintTolerations.value | default "false" -}}
{{- $taintTolerationsVal := fromYaml .Config.TaintTolerations.value -}}
{{- $isEvictionTolerations := .Config.EvictionTolerations.value | default "false" -}}
{{- $evictionTolerationsVal := fromYaml .Config.EvictionTolerations.value -}}
spec:
template:
spec:
tolerations:
{{- if ne $isTaintTolerations "false" }}
{{- range $k, $v := $taintTolerationsVal }}
-
{{- range $kk, $vv := $v }}
{{ $kk }}: {{ $vv }}
{{- end }}
{{- end }}
{{- end }}
{{- if ne $isEvictionTolerations "false" }}
{{- range $k, $v := $evictionTolerationsVal }}
-
{{- range $kk, $vv := $v }}
{{ $kk }}: {{ $vv }}
{{- end }}
{{- end }}
{{- end }}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.