1 Star 0 Fork 0

eezz10001/polardbx-operator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
k8s.go 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
eezz10001 提交于 2022-08-25 14:16 . x
/*
Copyright 2021 Alibaba Group Holding Limited.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package loader
import (
"context"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
bundle2 "gitee.com/eezz10001/polardbx-operator/pkg/util/config/bundle"
)
type K8sOptions struct {
Client client.Client
Key types.NamespacedName
}
type k8sLoader struct {
client client.Client
key types.NamespacedName
}
func (l *k8sLoader) loadSecret(ctx context.Context) (*corev1.Secret, error) {
var secret corev1.Secret
err := l.client.Get(ctx, l.key, &secret)
if err != nil {
return nil, err
}
return &secret, nil
}
func (l *k8sLoader) loadConfigMap(ctx context.Context) (*corev1.ConfigMap, error) {
var cm corev1.ConfigMap
err := l.client.Get(ctx, l.key, &cm)
if err != nil {
return nil, err
}
return &cm, nil
}
type k8sSecretLoader struct {
k8sLoader
}
func (l *k8sSecretLoader) Load(ctx context.Context) (bundle2.Bundle, error) {
secret, err := l.loadSecret(ctx)
if err != nil {
return nil, err
}
return bundle2.NewK8sSecretBundle(secret), nil
}
func NewK8sConfigMapLoader(opts K8sOptions) Loader {
return &k8sSecretLoader{
k8sLoader: k8sLoader{
client: opts.Client,
key: opts.Key,
},
}
}
type k8sConfigMapLoader struct {
k8sLoader
}
func (l *k8sConfigMapLoader) Load(ctx context.Context) (bundle2.Bundle, error) {
cm, err := l.loadConfigMap(ctx)
if err != nil {
return nil, err
}
return bundle2.NewK8sConfigMapBundle(cm), nil
}
func NewK8sSecretLoader(opts K8sOptions) Loader {
return &k8sConfigMapLoader{
k8sLoader: k8sLoader{
client: opts.Client,
key: opts.Key,
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/eezz10001/polardbx-operator.git
git@gitee.com:eezz10001/polardbx-operator.git
eezz10001
polardbx-operator
polardbx-operator
v1.0.2

搜索帮助