|
| 1 | +# Expansion Framework For TKEStack |
| 2 | + |
| 3 | +**Author**: madongdong([@MaDongdong99](https://github.com/MaDongdong99)) |
| 4 | + |
| 5 | +**Status** (20210413): Designing |
| 6 | + |
| 7 | +## Background |
| 8 | + |
| 9 | +[TKEStack Hook Framework](/docs/user/cluster/hooks.md) helps users to deploy the customized hooks to TKEStack, in which way user can inject customized logic during TKEStack life cycle. |
| 10 | + |
| 11 | +There are a group of hook points for users to choose and configure. Deep users will generate their own **tke.json** with hook points specified. |
| 12 | + |
| 13 | +Unfortunately, to make things work automatically, users usually need to generate the hook points by themselves so that it can work together with TKE-installer running. |
| 14 | +At the same time, users also need to make logic to deal with customized materials such as Images,Charts,Static-files etc, which TKEStack is able to handle. |
| 15 | + |
| 16 | +For automation, a **TKEStack Wrapper** is always needed to handle the scenes above, which deep users need to think about and cannot get help from TKEStack. |
| 17 | + |
| 18 | +## Motivation |
| 19 | + |
| 20 | +To make better use of TKEStack Hook Framework, in other words: **Do it A Native Way**, we consider **generating hook points** and **dealing with deploy materials** by a new mechanism: **Expansion Framework**. |
| 21 | + |
| 22 | +Expansion Framework will empower users to plan hook points while they are building their own packages, let TKEStack deal with customized materials, and then get rid of things such as **TKEStack Wrapper**. |
| 23 | + |
| 24 | +## Goals |
| 25 | + |
| 26 | +- Users put an **Expansion Package** at a specified place, start TKE-installer, and expansion framework will do all the rest. |
| 27 | +- Hook Points and Hook Files are auto setup. |
| 28 | +- Customized materials are auto uploaded. |
| 29 | +- When users disable expansion, TKEStack works as it did before. (And disable expansion means users do not put any **Expansion Package** in that place, which is also the same as what they did before) |
| 30 | + |
| 31 | +## Non Goals |
| 32 | + |
| 33 | +- Support multiple expansions. It's complicated to deal with conflicts between expansions, it's better to merge them together before packaging. |
| 34 | + |
| 35 | +## Design |
| 36 | + |
| 37 | +- Users make package layout as blow, and expansion framework does the following work: |
| 38 | + - Scan expansion directory to find expansion.yaml which specifies the layout |
| 39 | + - Verify files, hooks, images, charts materials |
| 40 | + - Merge hook config into tke.json |
| 41 | + - Copy hooks files into hook point |
| 42 | + - Put images, charts where they should be |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +### How it works |
| 47 | + |
| 48 | +- We define expansion.yaml as blow: which describes how users customize the hook framework. |
| 49 | + |
| 50 | +``` |
| 51 | +charts: [] |
| 52 | +images: [] |
| 53 | +files: [] |
| 54 | +hooks: [] |
| 55 | +provider: [] |
| 56 | +installer_skip_steps: [] |
| 57 | +create_cluster_skip_conditions: [] |
| 58 | +create_cluster_delegate_conditions: [] |
| 59 | +``` |
| 60 | + |
| 61 | +- charts: Users put their customized charts (maybe helm charts) into the ${EXPANSION_DIR}/charts directory, and expansion framework will scan & check them, then upload to a chart repo. |
| 62 | +- images: Users package their own images into ${EXPANSION_DIR}/images.tar.gz, and expansion framework will load/tag them, then push them to an image registry. |
| 63 | +- files: Users put cluster hook files(for cluster.CopyFile hook) into the ${EXPANSION_DIR}/files directory, and expansion framework will scan & check them, then merge to cluster.feature.files in tke.json. |
| 64 | +- hooks: User put install hook files(pre-install,post-cluster-ready,post-install) into the ${EXPANSION_DIR}/hooks directory, and expansion framework will scan & check them, then override origin hook files by them. |
| 65 | +- provider: User put provider files into ${EXPANSION_DIR}/provider directory, and expansion framework will override the origin provider files |
| 66 | +- installer_skip_steps: Install step list that users want to skip, expansion framework will merge them into config.Skipsteps in tke.json |
| 67 | +- create_cluster_skip_conditions: Create cluster conditions list that users want to skip, expansion framework will merge them into cluster.feature.skipConditions in tke.json |
| 68 | +- create_cluster_delegate_conditions: Create cluster conditions list that users want to delegate to an external operator, expansion framework will merge them into cluster.feature.delegateConditions(which is a new configuration for TKEStack) in tke.json |
| 69 | +- **note**: files may need to be rendered before they are copied. |
| 70 | + |
| 71 | +### Mechanism of **delegate_conditions** |
| 72 | + |
| 73 | +We introduce a new mechanism called delegate_conditions when creating cluster. |
| 74 | + |
| 75 | +This means TKEStack can delegate any condition(can be controlled by a whitelist) to an **external operator**, which will give users more abilities to customized their own TKEStack. |
| 76 | +For delegate_conditions, TKEStack do nothing but just waiting for the condition to be **READY**, an **external operator** will take responsibility. |
| 77 | + |
| 78 | +So an **external operator**(a beside container with tke-installer, or a sidecar with tke-platform), should complete conditions delegated to it and update cluster.Status.Conditions. |
| 79 | + |
| 80 | +What TKEStack need to do is providing an **expansion-operator-SDK** for users to develop their own operator. |
| 81 | + |
| 82 | +### Interactive Design |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +## Detailed design |
| 87 | + |
| 88 | +### Expansion Framework Modules |
| 89 | + |
| 90 | +- Expansion Framework Lib - Base functions to support the framework. |
| 91 | +- Expansion Operator SDK - If users want to develop expansion operator, give them a hand. |
| 92 | +- Expansion Build Tools - A tool collections for users to build/check/test their expansion package easily. |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +### Design of Expansion Framework module |
| 97 | + |
| 98 | +- expansion Driver module |
| 99 | + |
| 100 | +``` |
| 101 | +type expansionDriver struct { |
| 102 | + log log.Logger |
| 103 | + Operator string `json:"operator" yaml:"operator"` |
| 104 | + Values map[string]string |
| 105 | + Charts []string `json:"charts" yaml:"charts"` |
| 106 | + Files []string `json:"files" yaml:"files"` |
| 107 | + Hooks []string `json:"hooks" yaml:"hooks"` |
| 108 | + Provider []string `json:"provider" yaml:"provider"` |
| 109 | + Images []string `json:"images" yaml:"images"` |
| 110 | + globalKubeconfig []byte |
| 111 | + InstallerSkipSteps []string `json:"installer_skip_steps" yaml:"installer_skip_steps"` |
| 112 | + CreateClusterSkipConditions []string `json:"create_cluster_skip_conditions" yaml:"create_cluster_skip_conditions"` |
| 113 | + CreateClusterDelegateConditions []string `json:"create_cluster_delegate_conditions" yaml:"create_cluster_delegate_conditions"` |
| 114 | + // TODO: save image lists in case of installer restart to avoid load images again |
| 115 | + ImagesLoaded bool `json:"images_loaded" yaml:"images_loaded"` |
| 116 | + // if true, will prevent to pass the same expansion to cluster C |
| 117 | + DisablePassThroughToPlatform bool `json:"disable_pass_through_to_platform" yaml:"disable_pass_through_to_platform"` |
| 118 | +} |
| 119 | +``` |
| 120 | + |
| 121 | +- main method for TKEStack calling |
| 122 | + - scan() error |
| 123 | + - merge(t *TKE) |
| 124 | + - loadOperatorImage(ctx context.Context) error |
| 125 | + - patchHookFiles(ctx context.Context) error |
| 126 | + - startOperator(ctx context.Context) error |
| 127 | + - loadExpansionImages(ctx context.Context) error |
| 128 | + - tagExpansionImages(ctx context.Context) error |
| 129 | + - pushExpansionImages(ctx context.Context) error |
| 130 | + - uploadExpansionCharts(ctx context.Context) error |
| 131 | + |
| 132 | +### Changes in TKEStack |
| 133 | + |
| 134 | +- Global Changes |
| 135 | + - All modules with a cluster-installer (tke-installer, tke-platform-controller) add a member *expansionDriver, which supports calling of expansion functions. |
| 136 | + - All modules with a cluster.OnCreate method (tke-installer, tke-platform-controller) , when looping for createCluster, has break points for delegate steps, and do reload-cluster when the step fails. |
| 137 | +- Modules |
| 138 | + - apiv1.ClusterFeature add member "DelegateConditions []string" |
| 139 | + - cluster.Interface add const "ReasonDelegated = \"Delegated\"" |
| 140 | +- TKE-installer |
| 141 | + - tke.do() add "mergeFeatures()" |
| 142 | + - initSteps add "Load Expansion Operator Image", "Patch Hook Files", "Start Expansion Operator", |
| 143 | + - Step::loadImages add "loadExpansionImages" |
| 144 | + - Step::tagImages add "tagExpansionImages" |
| 145 | + - Step::pushImages add "pushExpansionImages" |
| 146 | + - Step::writeKubeconfig add "write kubeconfig to share dir" |
| 147 | +- tke-platform |
| 148 | + - TODO: |
| 149 | +- Cluster.Create |
| 150 | + - Split EnsureDocker into EnsureDocker and EnsureStartDocker |
| 151 | + - Split EnsureKubelet into EnsureKubelet and EnsureStartKubelet |
| 152 | + |
| 153 | + |
| 154 | +## Further Discussion |
| 155 | + |
| 156 | +- Addon expansion: giving a **Native Way** for user to install their own apps on TKEStack. |
0 commit comments