Path: blob/main/install/installer/pkg/components/docker-registry/secret.go
2501 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package dockerregistry56import (7"encoding/base64"8"encoding/json"9"fmt"1011"github.com/gitpod-io/gitpod/installer/pkg/common"12corev1 "k8s.io/api/core/v1"13metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"14"k8s.io/apimachinery/pkg/runtime"15"k8s.io/kubectl/pkg/cmd/create"16"k8s.io/utils/pointer"17)1819func secret(ctx *common.RenderContext) ([]runtime.Object, error) {20if !pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {21return nil, nil22}2324user := ctx.Values.InternalRegistryUsername25if user == "" {26return nil, fmt.Errorf("unknown value: internal registry username")27}2829password := ctx.Values.InternalRegistryPassword30if password == "" {31return nil, fmt.Errorf("unknown value: internal registry password")32}3334// todo(sje): handle if bypassing registry with proxy35registryHost := "registry." + ctx.Config.Domain3637config, err := json.Marshal(create.DockerConfigJSON{38Auths: map[string]create.DockerConfigEntry{39registryHost: {40Auth: base64.StdEncoding.EncodeToString([]byte(user + ":" + password)),41},42},43})44if err != nil {45return nil, err46}4748return []runtime.Object{&corev1.Secret{49TypeMeta: common.TypeMetaSecret,50ObjectMeta: metav1.ObjectMeta{51Name: BuiltInRegistryAuth,52Namespace: ctx.Namespace,53Labels: common.DefaultLabels(Component),54},55Type: corev1.SecretTypeDockerConfigJson,56Data: map[string][]byte{57".dockerconfigjson": config,58"user": []byte(user),59"password": []byte(password),60},61}}, nil62}636465