-
Notifications
You must be signed in to change notification settings - Fork 88
/
brand.go
61 lines (51 loc) · 1.82 KB
/
brand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package identity
import (
"context"
"github.com/pkg/errors"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
)
func getWebConfig(ctx context.Context, clientset kubernetes.Interface, namespace string, singleApp bool) (*kotsv1beta1.IdentityWebConfig, error) {
webConfig := &kotsv1beta1.IdentityWebConfig{
Title: "Admin Console",
Theme: &kotsv1beta1.IdentityWebConfigTheme{
StyleCSSBase64: KotsStyleCSSBase64,
LogoURL: KotsLogoURL,
FaviconBase64: KotsFaviconBase64,
},
}
if !singleApp {
return webConfig, nil
}
brandingConfigMap, err := clientset.CoreV1().ConfigMaps(namespace).Get(ctx, "kotsadm-application-metadata", metav1.GetOptions{})
if kuberneteserrors.IsNotFound(err) {
return webConfig, nil
} else if err != nil {
return webConfig, errors.Wrap(err, "failed to get branding config map")
}
data, ok := brandingConfigMap.Data["application.yaml"]
if !ok {
return webConfig, errors.New("branding config map has no application.yaml")
}
// parse data as a kotskind
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, gvk, err := decode([]byte(data), nil, nil)
if err != nil {
return webConfig, errors.Wrap(err, "failed to decode application gvk")
}
if gvk.Group != "kots.io" || gvk.Version != "v1beta1" || gvk.Kind != "Application" {
return webConfig, errors.New("unexpected gvk found in metadata")
}
application := obj.(*kotsv1beta1.Application)
if application.Spec.Icon != "" {
webConfig.Theme.LogoURL = application.Spec.Icon
}
if application.Spec.Title != "" {
webConfig.Title = application.Spec.Title
}
// TODO: we don't really support base64 here for favicon
return webConfig, nil
}