44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
//
|
|
// Copyright (c) 2019-2023 Red Hat, Inc.
|
|
// This program and the accompanying materials are made
|
|
// available under the terms of the Eclipse Public License 2.0
|
|
// which is available at https://www.eclipse.org/legal/epl-2.0/
|
|
//
|
|
// SPDX-License-Identifier: EPL-2.0
|
|
//
|
|
// Contributors:
|
|
// Red Hat, Inc. - initial API and implementation
|
|
//
|
|
|
|
package deploy
|
|
|
|
import (
|
|
"github.com/eclipse-che/che-operator/pkg/common/chetypes"
|
|
defaults "github.com/eclipse-che/che-operator/pkg/common/operator-defaults"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func SyncServiceAccountToCluster(deployContext *chetypes.DeployContext, name string) (bool, error) {
|
|
saSpec := getServiceAccountSpec(deployContext, name)
|
|
_, err := CreateIfNotExists(deployContext, saSpec)
|
|
return err == nil, err
|
|
}
|
|
|
|
func getServiceAccountSpec(deployContext *chetypes.DeployContext, name string) *corev1.ServiceAccount {
|
|
labels := GetLabels(defaults.GetCheFlavor())
|
|
serviceAccount := &corev1.ServiceAccount{
|
|
TypeMeta: metav1.TypeMeta{
|
|
Kind: "ServiceAccount",
|
|
APIVersion: "v1",
|
|
},
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: name,
|
|
Namespace: deployContext.CheCluster.Namespace,
|
|
Labels: labels,
|
|
},
|
|
}
|
|
|
|
return serviceAccount
|
|
}
|