代码拉取完成,页面将自动刷新
/*
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,
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。