Files
velero/pkg/builder/secret_key_selector_builder.go
Bridget McErlean 9dbd238c89 Use controller-runtime client to get restic secrets (#3320)
* Use kubebuilder client for fetching restic secrets

Instead of using a SecretInformer for fetching secrets for restic, use
the cached client provided by the controller-runtime manager.

In order to use this client, the scheme for Secrets must be added to the
scheme used by the manager so this is added when creating the manager in
both the velero and restic servers.

This change also refactors some of the tests to add a shared utility for
creating a fake controller-runtime client which is now used among all
tests which use that client. This has been added to ensure that all
tests use the same client with the same scheme.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>

* Add builder for SecretKeySelector

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
2021-02-18 10:30:52 -08:00

44 lines
1.2 KiB
Go

/*
Copyright the Velero contributors.
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 builder
import (
corev1api "k8s.io/api/core/v1"
)
// SecretKeySelectorBuilder builds SecretKeySelector objects.
type SecretKeySelectorBuilder struct {
object *corev1api.SecretKeySelector
}
// ForSecretKeySelector is the constructor for a SecretKeySelectorBuilder.
func ForSecretKeySelector(name string, key string) *SecretKeySelectorBuilder {
return &SecretKeySelectorBuilder{
object: &corev1api.SecretKeySelector{
LocalObjectReference: corev1api.LocalObjectReference{
Name: name,
},
Key: key,
},
}
}
// Result returns the built SecretKeySelector.
func (b *SecretKeySelectorBuilder) Result() *corev1api.SecretKeySelector {
return b.object
}