Skip to content

Commit d4ad561

Browse files
androndomyasnikovdaniil
authored andcommitted
fix(backups): report sizeBytes for MariaDB backup artifacts
Backup.status.artifact.sizeBytes was only ever set by the etcd strategy, so MariaDB backups always arrived without a size. mariadb-operator writes each logical dump as <prefix>/backup.<RFC3339>[.<compression>].sql under a prefix shared by every backup of the application, and the URI the driver records is synthetic, so there is no single object to HEAD. On completion the driver now lists the prefix with the tenant credentials the operator Backup was rendered with and takes the size of the one dump whose timestamp falls inside the operator Backup's lifetime. When the bucket cannot be read or the window does not match exactly one dump, the field stays unset. The API doc now states that an absent sizeBytes means "unknown", and the Velero strategy documents why it leaves the field unset: kopia stores data content-addressed across backups, so there is no per-backup stored size. Refs cozystack#4316 Assisted-by: LLM Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 4087218 commit d4ad561

9 files changed

Lines changed: 473 additions & 5 deletions

File tree

‎api/backups/v1alpha1/backup_types.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ type BackupArtifact struct {
3737
// For example: s3://bucket/prefix/file.tar.gz
3838
URI string `json:"uri"`
3939

40-
// SizeBytes is the size of the artifact in bytes, if known.
40+
// SizeBytes is the size of the artifact in bytes, if known. Drivers
41+
// leave it unset rather than writing 0 when they cannot measure the
42+
// stored size, so an absent value means "unknown", not "empty".
4143
// +optional
4244
SizeBytes int64 `json:"sizeBytes,omitempty"`
4345

‎go.mod‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/go-logr/logr v1.4.4
1717
github.com/go-logr/zapr v1.3.0
1818
github.com/go-task/slim-sprig/v3 v3.0.0
19+
github.com/minio/minio-go/v7 v7.0.98
1920
github.com/onsi/ginkgo/v2 v2.33.0
2021
github.com/onsi/gomega v1.43.1
2122
github.com/prometheus/client_golang v1.24.1
@@ -63,6 +64,7 @@ require (
6364
github.com/fsnotify/fsnotify v1.10.1 // indirect
6465
github.com/fxamacker/cbor/v2 v2.9.4 // indirect
6566
github.com/gkampitakis/go-snaps v0.5.23 // indirect
67+
github.com/go-ini/ini v1.67.0 // indirect
6668
github.com/go-logr/stdr v1.2.2 // indirect
6769
github.com/go-openapi/jsonpointer v1.0.1 // indirect
6870
github.com/go-openapi/jsonreference v1.0.2 // indirect
@@ -93,18 +95,25 @@ require (
9395
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9496
github.com/json-iterator/go v1.1.12 // indirect
9597
github.com/klauspost/compress v1.20.0 // indirect
98+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
99+
github.com/klauspost/crc32 v1.3.0 // indirect
96100
github.com/kylelemons/godebug v1.1.0 // indirect
101+
github.com/minio/crc64nvme v1.1.1 // indirect
102+
github.com/minio/md5-simd v1.1.2 // indirect
97103
github.com/moby/spdystream v0.5.1 // indirect
98104
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
99105
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
100106
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
107+
github.com/philhofer/fwd v1.2.0 // indirect
101108
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
102109
github.com/prometheus/client_model v0.6.3 // indirect
103110
github.com/prometheus/common v0.71.0 // indirect
104111
github.com/prometheus/procfs v0.22.0 // indirect
105112
github.com/rogpeppe/go-internal v1.16.0 // indirect
113+
github.com/rs/xid v1.6.0 // indirect
106114
github.com/sirupsen/logrus v1.10.2 // indirect
107115
github.com/tidwall/match v1.2.0 // indirect
116+
github.com/tinylib/msgp v1.6.1 // indirect
108117
github.com/x448/float16 v0.8.4 // indirect
109118
go.etcd.io/etcd/api/v3 v3.7.0 // indirect
110119
go.etcd.io/etcd/client/pkg/v3 v3.7.0 // indirect

‎go.sum‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/gkampitakis/ciinfo v0.3.4 h1:5eBSibVuSMbb/H6Elc0IIEFbkzCJi3lm94n0+U7Z
6161
github.com/gkampitakis/ciinfo v0.3.4/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
6262
github.com/gkampitakis/go-snaps v0.5.23 h1:okh5QR48zpUjpWtu65AtqxdCY8huJq+dEDuUzd1PuKg=
6363
github.com/gkampitakis/go-snaps v0.5.23/go.mod h1:uy3lVzCCRRsAwYqSocyw5fY8xRLCYEfqoOJNxr8HonM=
64+
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
65+
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
6466
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
6567
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
6668
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -141,6 +143,11 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
141143
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
142144
github.com/klauspost/compress v1.20.0 h1:a3C1ke2ohxFymNlb2HWAHjDeKCI90scRskErZkR0ezA=
143145
github.com/klauspost/compress v1.20.0/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
146+
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
147+
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
148+
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
149+
github.com/klauspost/crc32 v1.3.0 h1:sSmTt3gUt81RP655XGZPElI0PelVTZ6YwCRnPSupoFM=
150+
github.com/klauspost/crc32 v1.3.0/go.mod h1:D7kQaZhnkX/Y0tstFGf8VUzv2UofNGqCjnC3zdHB0Hw=
144151
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
145152
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
146153
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -151,6 +158,12 @@ github.com/maruel/natural v1.3.0 h1:VsmCsBmEyrR46RomtgHs5hbKADGRVtliHTyCOLFBpsg=
151158
github.com/maruel/natural v1.3.0/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
152159
github.com/mfridman/tparse v0.18.0 h1:wh6dzOKaIwkUGyKgOntDW4liXSo37qg5AXbIhkMV3vE=
153160
github.com/mfridman/tparse v0.18.0/go.mod h1:gEvqZTuCgEhPbYk/2lS3Kcxg1GmTxxU7kTC8DvP0i/A=
161+
github.com/minio/crc64nvme v1.1.1 h1:8dwx/Pz49suywbO+auHCBpCtlW1OfpcLN7wYgVR6wAI=
162+
github.com/minio/crc64nvme v1.1.1/go.mod h1:eVfm2fAzLlxMdUGc0EEBGSMmPwmXD5XiNRpnu9J3bvg=
163+
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
164+
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
165+
github.com/minio/minio-go/v7 v7.0.98 h1:MeAVKjLVz+XJ28zFcuYyImNSAh8Mq725uNW4beRisi0=
166+
github.com/minio/minio-go/v7 v7.0.98/go.mod h1:cY0Y+W7yozf0mdIclrttzo1Iiu7mEf9y7nk2uXqMOvM=
154167
github.com/moby/spdystream v0.5.1 h1:9sNYeYZUcci9R6/w7KDaFWEWeV4LStVG78Mpyq/Zm/Y=
155168
github.com/moby/spdystream v0.5.1/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
156169
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -165,6 +178,8 @@ github.com/onsi/ginkgo/v2 v2.33.0 h1:C8gBA6Uc2ZEubiV+SXiu5tZnMTwEmXHgkJwGozKtZf8
165178
github.com/onsi/ginkgo/v2 v2.33.0/go.mod h1:+aXOY+vzZ5mu2iI2HpTZUPmM//oQfsNFX6gU9kNcA44=
166179
github.com/onsi/gomega v1.43.1 h1:vGIPFuYrIO6/0Z09s0I0QQQgFchiX4+tb1re3MScJYo=
167180
github.com/onsi/gomega v1.43.1/go.mod h1:e/C2HwaZ1DhvjzXXuFhcR7hY7Sh9pl7MmoWKEjzwcdA=
181+
github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM=
182+
github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM=
168183
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
169184
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
170185
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -180,6 +195,8 @@ github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
180195
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
181196
github.com/rogpeppe/go-internal v1.16.0 h1:O9DK+vNMDVGLr2BeZqmpLeMjiMNkuXfcqntWbZV6S5g=
182197
github.com/rogpeppe/go-internal v1.16.0/go.mod h1:DrUVZyrJU+txYW5/1kwtXQSMFio52ZOxX7yM1VHvnxs=
198+
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
199+
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
183200
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
184201
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
185202
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
@@ -206,6 +223,8 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
206223
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
207224
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
208225
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
226+
github.com/tinylib/msgp v1.6.1 h1:ESRv8eL3u+DNHUoSAAQRE50Hm162zqAnBoGv9PzScPY=
227+
github.com/tinylib/msgp v1.6.1/go.mod h1:RSp0LW9oSxFut3KzESt5Voq4GVWyS+PSulT77roAqEA=
209228
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 h1:6fotK7otjonDflCTK0BCfls4SPy3NcCVb5dqqmbRknE=
210229
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75/go.mod h1:KO6IkyS8Y3j8OdNO85qEYBsRPuteD+YciPomcXdrMnk=
211230
github.com/vmware-tanzu/velero v1.18.3 h1:9uwN5yxTWQl9PsF5ljX4xiG+7VIq3I9mxOQ0DyyZ31A=

‎internal/backupcontroller/backupjob_controller.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type BackupJobReconciler struct {
3939
// re-reads the BackupJob before dispatching to a driver. Wired in
4040
// SetupWithManager.
4141
APIReader client.Reader
42+
43+
// newS3ObjectLister overrides the S3 client used to measure artifact
44+
// sizes; nil means a real minio client. Set by unit tests.
45+
newS3ObjectLister func(ctx context.Context, namespace string, s3 *strategyv1alpha1.MariaDBS3Template) (s3ObjectLister, error)
4246
}
4347

4448
func (r *BackupJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package backupcontroller
3+
4+
import (
5+
"context"
6+
"crypto/tls"
7+
"crypto/x509"
8+
"fmt"
9+
"net/http"
10+
"strings"
11+
"time"
12+
13+
"github.com/minio/minio-go/v7"
14+
"github.com/minio/minio-go/v7/pkg/credentials"
15+
corev1 "k8s.io/api/core/v1"
16+
"k8s.io/apimachinery/pkg/types"
17+
18+
strategyv1alpha1 "github.com/cozystack/cozystack/api/backups/strategy/v1alpha1"
19+
"github.com/cozystack/cozystack/internal/backupcontroller/mariadbtypes"
20+
)
21+
22+
const (
23+
mariadbSizeProbeTimeout = 30 * time.Second
24+
25+
// Slack around the [created, completed] window of the operator Backup
26+
// when matching the timestamp mariadb-operator embeds in the dump file
27+
// name: that timestamp comes from the backup Job pod's clock, not the
28+
// apiserver's, and is truncated to seconds.
29+
mariadbSizeProbeClockSkew = time.Minute
30+
)
31+
32+
type s3ObjectInfo struct {
33+
Key string
34+
Size int64
35+
}
36+
37+
type s3ObjectLister interface {
38+
ListObjects(ctx context.Context, bucket, prefix string) ([]s3ObjectInfo, error)
39+
}
40+
41+
// mariadbArtifactSizeBytes measures the dump mariadb-operator uploaded for
42+
// mdbBackup. The strategy prefix is shared by every backup of the
43+
// application, so the dump is identified by the timestamp in its file name
44+
// falling inside the operator Backup's lifetime. Returns 0 - leaving
45+
// Artifact.SizeBytes absent - when the object store cannot be read or the
46+
// window does not match exactly one dump: an unknown size must not be
47+
// reported as a measured one.
48+
func (r *BackupJobReconciler) mariadbArtifactSizeBytes(
49+
ctx context.Context,
50+
namespace string,
51+
s3 *strategyv1alpha1.MariaDBS3Template,
52+
mdbBackup *mariadbtypes.Backup,
53+
completedAt time.Time,
54+
) int64 {
55+
logger := getLogger(ctx)
56+
ctx, cancel := context.WithTimeout(ctx, mariadbSizeProbeTimeout)
57+
defer cancel()
58+
59+
newLister := r.newS3ObjectLister
60+
if newLister == nil {
61+
newLister = r.newMariaDBMinioLister
62+
}
63+
lister, err := newLister(ctx, namespace, s3)
64+
if err != nil {
65+
logger.Debug("cannot build S3 client to measure MariaDB backup size", "backup", mdbBackup.Name, "error", err)
66+
return 0
67+
}
68+
prefix := mariadbOperatorS3Prefix(s3.Prefix)
69+
objects, err := lister.ListObjects(ctx, s3.Bucket, prefix)
70+
if err != nil {
71+
logger.Debug("cannot list MariaDB backup objects to measure size", "backup", mdbBackup.Name, "error", err)
72+
return 0
73+
}
74+
75+
lower := mdbBackup.CreationTimestamp.Add(-mariadbSizeProbeClockSkew)
76+
upper := completedAt.Add(mariadbSizeProbeClockSkew)
77+
var matched []s3ObjectInfo
78+
for _, obj := range objects {
79+
ts, ok := parseMariaDBLogicalBackupFile(strings.TrimPrefix(obj.Key, prefix))
80+
if !ok || ts.Before(lower) || ts.After(upper) {
81+
continue
82+
}
83+
matched = append(matched, obj)
84+
}
85+
if len(matched) != 1 {
86+
logger.Debug("MariaDB backup dump not attributable to a single object; leaving size unset",
87+
"backup", mdbBackup.Name, "candidates", len(matched))
88+
return 0
89+
}
90+
return matched[0].Size
91+
}
92+
93+
// mariadbOperatorS3Prefix mirrors how mariadb-operator normalises
94+
// spec.storage.s3.prefix before prepending it to object keys.
95+
func mariadbOperatorS3Prefix(prefix string) string {
96+
if prefix == "" || prefix == "/" {
97+
return ""
98+
}
99+
if !strings.HasSuffix(prefix, "/") {
100+
return prefix + "/"
101+
}
102+
return prefix
103+
}
104+
105+
// parseMariaDBLogicalBackupFile accepts the logical-backup file names
106+
// mariadb-operator writes, backup.<RFC3339>.sql and
107+
// backup.<RFC3339>.<compression>.sql, and returns the embedded timestamp.
108+
func parseMariaDBLogicalBackupFile(name string) (time.Time, bool) {
109+
parts := strings.Split(name, ".")
110+
if len(parts) != 3 && len(parts) != 4 {
111+
return time.Time{}, false
112+
}
113+
if parts[0] != "backup" || parts[len(parts)-1] != "sql" {
114+
return time.Time{}, false
115+
}
116+
ts, err := time.Parse(time.RFC3339, parts[1])
117+
if err != nil {
118+
return time.Time{}, false
119+
}
120+
return ts, true
121+
}
122+
123+
type minioObjectLister struct {
124+
client *minio.Client
125+
}
126+
127+
func (l *minioObjectLister) ListObjects(ctx context.Context, bucket, prefix string) ([]s3ObjectInfo, error) {
128+
var out []s3ObjectInfo
129+
for obj := range l.client.ListObjects(ctx, bucket, minio.ListObjectsOptions{Prefix: prefix}) {
130+
if obj.Err != nil {
131+
return nil, obj.Err
132+
}
133+
out = append(out, s3ObjectInfo{Key: obj.Key, Size: obj.Size})
134+
}
135+
return out, nil
136+
}
137+
138+
// newMariaDBMinioLister builds an S3 client from the same Secrets and TLS
139+
// settings the operator Backup was rendered with, so the controller reads
140+
// the bucket with the tenant's credentials rather than its own.
141+
func (r *BackupJobReconciler) newMariaDBMinioLister(ctx context.Context, namespace string, s3 *strategyv1alpha1.MariaDBS3Template) (s3ObjectLister, error) {
142+
accessKey, err := r.mariadbSecretValue(ctx, namespace, s3.AccessKeyIDSecretKeyRef)
143+
if err != nil {
144+
return nil, err
145+
}
146+
secretKey, err := r.mariadbSecretValue(ctx, namespace, s3.SecretAccessKeySecretKeyRef)
147+
if err != nil {
148+
return nil, err
149+
}
150+
var sessionToken string
151+
if s3.SessionTokenSecretKeyRef != nil {
152+
if sessionToken, err = r.mariadbSecretValue(ctx, namespace, *s3.SessionTokenSecretKeyRef); err != nil {
153+
return nil, err
154+
}
155+
}
156+
157+
opts := &minio.Options{
158+
Creds: credentials.NewStaticV4(accessKey, secretKey, sessionToken),
159+
Region: s3.Region,
160+
Secure: s3.TLS != nil && s3.TLS.Enabled,
161+
}
162+
if opts.Secure && s3.TLS.CASecretKeyRef != nil {
163+
caPEM, err := r.mariadbSecretValue(ctx, namespace, *s3.TLS.CASecretKeyRef)
164+
if err != nil {
165+
return nil, err
166+
}
167+
pool, err := x509.SystemCertPool()
168+
if err != nil {
169+
pool = x509.NewCertPool()
170+
}
171+
if !pool.AppendCertsFromPEM([]byte(caPEM)) {
172+
return nil, fmt.Errorf("no PEM certificates in Secret %s/%s key %q", namespace, s3.TLS.CASecretKeyRef.Name, s3.TLS.CASecretKeyRef.Key)
173+
}
174+
opts.Transport = &http.Transport{TLSClientConfig: &tls.Config{RootCAs: pool, MinVersion: tls.VersionTLS12}}
175+
}
176+
client, err := minio.New(s3.Endpoint, opts)
177+
if err != nil {
178+
return nil, err
179+
}
180+
return &minioObjectLister{client: client}, nil
181+
}
182+
183+
func (r *BackupJobReconciler) mariadbSecretValue(ctx context.Context, namespace string, ref strategyv1alpha1.MariaDBSecretKeySelector) (string, error) {
184+
secret := &corev1.Secret{}
185+
if err := r.Get(ctx, types.NamespacedName{Namespace: namespace, Name: ref.Name}, secret); err != nil {
186+
return "", err
187+
}
188+
v, ok := secret.Data[ref.Key]
189+
if !ok {
190+
return "", fmt.Errorf("Secret %s/%s has no key %q", namespace, ref.Name, ref.Key)
191+
}
192+
return string(v), nil
193+
}

0 commit comments

Comments
 (0)