@@ -26,6 +26,11 @@ import (
2626 "github.com/replicatedhq/helmvm/pkg/preflights"
2727)
2828
29+ const (
30+ clusterConfigMapName = "embedded-cluster-config"
31+ clusterConfigMapNS = "kube-system"
32+ )
33+
2934// ParsedSection holds the parsed section from the binary. We only care about the
3035// application object, whatever HostPreflight we can find, and the app License.
3136type ParsedSection struct {
@@ -122,12 +127,20 @@ func (a *AdminConsoleCustomization) kubeClient() (client.Client, error) {
122127
123128// apply will attempt to read the helmvm binary and extract the kotsadm portal customization
124129// from it. If it finds one, it will apply it to the cluster.
125- func (a * AdminConsoleCustomization ) apply (ctx context.Context ) error {
130+ func (a * AdminConsoleCustomization ) apply (ctx context.Context , version string ) error {
126131 logrus .Infof ("Applying admin console customization" )
127132 if runtime .GOOS != "linux" {
128133 logrus .Infof ("Skipping admin console customization on %s" , runtime .GOOS )
129134 return nil
130135 }
136+ if err := a .kotsConfig (ctx ); err != nil {
137+ return err
138+ }
139+ return a .clusterConfig (ctx , version )
140+ }
141+
142+ // kotsConfig reads the embedded kots config and creates it in the cluster.
143+ func (a * AdminConsoleCustomization ) kotsConfig (ctx context.Context ) error {
131144 cust , err := a .extractCustomization ()
132145 if err != nil {
133146 return fmt .Errorf ("unable to extract customization from binary: %w" , err )
@@ -170,6 +183,37 @@ func (a *AdminConsoleCustomization) apply(ctx context.Context) error {
170183 return nil
171184}
172185
186+ // clusterConfig makes sure a config map named "embedded-cluster-config" exists in the cluster.
187+ // XXX this will eventually be customizable by the user through the app release.
188+ func (a * AdminConsoleCustomization ) clusterConfig (ctx context.Context , version string ) error {
189+ kubeclient , err := a .kubeClient ()
190+ if err != nil {
191+ return fmt .Errorf ("unable to create kubernetes client: %w" , err )
192+ }
193+ nsn := client.ObjectKey {Namespace : clusterConfigMapNS , Name : clusterConfigMapName }
194+ var cm corev1.ConfigMap
195+ if err := kubeclient .Get (ctx , nsn , & cm ); err != nil {
196+ if ! errors .IsNotFound (err ) {
197+ return fmt .Errorf ("unable to get cluster config configmap: %w" , err )
198+ }
199+ logrus .Infof ("Creating cluster config configmap" )
200+ cm = corev1.ConfigMap {
201+ ObjectMeta : metav1.ObjectMeta {Namespace : nsn .Namespace , Name : nsn .Name },
202+ Data : map [string ]string {"version" : version },
203+ }
204+ if err := kubeclient .Create (ctx , & cm ); err != nil {
205+ return fmt .Errorf ("unable to create cluster config configmap: %w" , err )
206+ }
207+ return nil
208+ }
209+ logrus .Infof ("Updating cluster config configmap" )
210+ cm .Data ["version" ] = version
211+ if err := kubeclient .Update (ctx , & cm ); err != nil {
212+ return fmt .Errorf ("unable to update cluster config configmap: %w" , err )
213+ }
214+ return nil
215+ }
216+
173217// hostPreflights returns a list of HostPreflight specs that are found in the binary.
174218// These are part of the embedded Kots Application Release.
175219func (a * AdminConsoleCustomization ) hostPreflights () (* v1beta2.HostPreflightSpec , error ) {
0 commit comments