forked from k3s-io/k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add etcd s3 config secret implementation
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
- Loading branch information
Showing
14 changed files
with
407 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package etcd | ||
|
||
import ( | ||
"encoding/base64" | ||
"reflect" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/k3s-io/k3s/pkg/daemons/config" | ||
"github.com/sirupsen/logrus" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// withS3ConfigSecret returns a modified ETCD struct that is overriden | ||
// with etcd S3 snapshot config from the secret. | ||
// If the secret does not exist, the etcd struct is returned unmodified. | ||
func (e *ETCD) withS3ConfigSecret() *ETCD { | ||
if e.config.Runtime == nil || e.config.EtcdS3 == nil || e.config.EtcdS3.ConfigSecret == "" { | ||
return e | ||
} | ||
|
||
// The ConfigSecret and Timeout fields should be ignored when checking | ||
// to see if the current configuration should prevent the Secret from being used. | ||
defaultEtcdS3 := &config.EtcdS3{ | ||
ConfigSecret: e.config.EtcdS3.ConfigSecret, | ||
Timeout: metav1.Duration{ | ||
Duration: 5 * time.Minute, | ||
}, | ||
} | ||
|
||
if !reflect.DeepEqual(e.config.EtcdS3, defaultEtcdS3) { | ||
logrus.Infof("Ignoring S3 config from etcd-s3-config-secret %s: S3 configuration is already present", e.config.EtcdS3.ConfigSecret) | ||
return e | ||
} | ||
|
||
secret, err := e.config.Runtime.Core.Core().V1().Secret().Get(metav1.NamespaceSystem, e.config.EtcdS3.ConfigSecret, metav1.GetOptions{}) | ||
if err != nil { | ||
if !apierrors.IsNotFound(err) { | ||
logrus.Warnf("Failed to get Secret for etcd-s3-config-secret %s: %v", e.config.EtcdS3.ConfigSecret, err) | ||
} | ||
return e | ||
} | ||
|
||
logrus.Infof("Using S3 config from etcd-config-secret %s", e.config.EtcdS3.ConfigSecret) | ||
caBundles := []string{} | ||
re := &ETCD{ | ||
client: e.client, | ||
config: &config.Control{ | ||
CriticalControlArgs: e.config.CriticalControlArgs, | ||
Runtime: e.config.Runtime, | ||
DataDir: e.config.DataDir, | ||
Datastore: e.config.Datastore, | ||
EtcdSnapshotCompress: e.config.EtcdSnapshotCompress, | ||
EtcdSnapshotDir: e.config.EtcdSnapshotDir, | ||
EtcdSnapshotName: e.config.EtcdSnapshotName, | ||
EtcdSnapshotRetention: e.config.EtcdSnapshotRetention, | ||
}, | ||
name: e.name, | ||
address: e.address, | ||
cron: e.cron, | ||
cancel: e.cancel, | ||
snapshotSem: e.snapshotSem, | ||
} | ||
re.config.EtcdS3 = &config.EtcdS3{ | ||
AccessKey: string(secret.Data["etcd-s3-access-key"]), | ||
Bucket: string(secret.Data["etcd-s3-bucket"]), | ||
Endpoint: string(secret.Data["etcd-s3-endpoint"]), | ||
Folder: string(secret.Data["etcd-s3-folder"]), | ||
Proxy: string(secret.Data["etcd-s3-proxy"]), | ||
Region: string(secret.Data["etcd-s3-region"]), | ||
SecretKey: string(secret.Data["etcd-s3-secret-key"]), | ||
} | ||
|
||
re.config.EtcdS3.SkipSSLVerify, err = strconv.ParseBool(string(secret.Data["etcd-s3-skip-ssl-verify"])) | ||
if err != nil { | ||
logrus.Warnf("Failed to parse etcd-s3-skip-ssl-verify value from S3 config secret %s: %v", e.config.EtcdS3.ConfigSecret, err) | ||
} | ||
|
||
re.config.EtcdS3.Insecure, err = strconv.ParseBool(string(secret.Data["etcd-s3-insecure"])) | ||
if err != nil { | ||
logrus.Warnf("Failed to parse etcd-s3-insecure value from S3 config secret %s: %v", e.config.EtcdS3.ConfigSecret, err) | ||
} | ||
|
||
re.config.EtcdS3.Timeout.Duration, err = time.ParseDuration(string(secret.Data["etcd-s3-timeout"])) | ||
if err != nil { | ||
logrus.Warnf("Failed to parse etcd-s3-timeout value from S3 config secret %s: %v", e.config.EtcdS3.ConfigSecret, err) | ||
} | ||
|
||
// Add inline CA bundle if set | ||
if len(secret.Data["etcd-s3-endpoint-ca"]) > 0 { | ||
caBundles = append(caBundles, base64.StdEncoding.EncodeToString(secret.Data["etcd-s3-endpoint-ca"])) | ||
} | ||
|
||
// Add CA bundles from named configmap if set | ||
if caConfigMapName := string(secret.Data["etcd-s3-endpoint-ca-name"]); caConfigMapName != "" { | ||
configMap, err := e.config.Runtime.Core.Core().V1().ConfigMap().Get(metav1.NamespaceSystem, caConfigMapName, metav1.GetOptions{}) | ||
if err != nil { | ||
logrus.Warnf("Failed to get ConfigMap %s for etcd-s3-endpoint-ca-name value from S3 config secret %s: %v", caConfigMapName, e.config.EtcdS3.ConfigSecret, err) | ||
} else { | ||
for _, v := range configMap.Data { | ||
caBundles = append(caBundles, base64.StdEncoding.EncodeToString([]byte(v))) | ||
} | ||
for _, v := range configMap.BinaryData { | ||
caBundles = append(caBundles, base64.StdEncoding.EncodeToString(v)) | ||
} | ||
} | ||
} | ||
|
||
// Concatenate all requested CA bundle strings into config var | ||
re.config.EtcdS3.EndpointCA = strings.Join(caBundles, " ") | ||
|
||
return re | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.