-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8005 from cPu1/zonal-shift
Support EKS zonal shift config
- Loading branch information
Showing
13 changed files
with
218 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# An example ClusterConfig that uses EKS Zonal Shift. | ||
|
||
apiVersion: eksctl.io/v1alpha5 | ||
kind: ClusterConfig | ||
|
||
metadata: | ||
name: highly-available-cluster | ||
region: us-west-2 | ||
|
||
zonalShiftConfig: | ||
enabled: true |
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,33 @@ | ||
package cmdutils | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// NewZonalShiftConfigLoader creates a new loader for zonal shift config. | ||
func NewZonalShiftConfigLoader(cmd *Cmd) ClusterConfigLoader { | ||
l := newCommonClusterConfigLoader(cmd) | ||
l.flagsIncompatibleWithConfigFile.Insert( | ||
"enable-zonal-shift", | ||
"cluster", | ||
) | ||
|
||
l.validateWithConfigFile = func() error { | ||
if cmd.NameArg != "" { | ||
return fmt.Errorf("config file and enable-zonal-shift %s", IncompatibleFlags) | ||
} | ||
if l.ClusterConfig.ZonalShiftConfig == nil || l.ClusterConfig.ZonalShiftConfig.Enabled == nil { | ||
return errors.New("field zonalShiftConfig.enabled is required") | ||
} | ||
return nil | ||
} | ||
|
||
l.validateWithoutConfigFile = func() error { | ||
if !cmd.CobraCommand.Flag("enable-zonal-shift").Changed { | ||
return errors.New("--enable-zonal-shift is required when a config file is not specified") | ||
} | ||
return nil | ||
} | ||
return l | ||
} |
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,84 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/eks" | ||
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types" | ||
|
||
"github.com/kris-nova/logger" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
|
||
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" | ||
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils" | ||
) | ||
|
||
func updateZonalShiftConfig(cmd *cmdutils.Cmd, handler func(*cmdutils.Cmd) error) { | ||
cfg := api.NewClusterConfig() | ||
cmd.ClusterConfig = cfg | ||
|
||
cmd.SetDescription("update-zonal-shift-config", "update zonal shift config", "update zonal shift config on a cluster") | ||
|
||
var enableZonalShift bool | ||
cmd.CobraCommand.RunE = func(_ *cobra.Command, args []string) error { | ||
cmd.NameArg = cmdutils.GetNameArg(args) | ||
if err := cmdutils.NewZonalShiftConfigLoader(cmd).Load(); err != nil { | ||
return err | ||
} | ||
if cmd.ClusterConfigFile == "" { | ||
cfg.ZonalShiftConfig = &api.ZonalShiftConfig{ | ||
Enabled: &enableZonalShift, | ||
} | ||
} | ||
return handler(cmd) | ||
} | ||
|
||
cmdutils.AddCommonFlagsForAWS(cmd, &cmd.ProviderConfig, false) | ||
|
||
cmd.FlagSetGroup.InFlagSet("General", func(fs *pflag.FlagSet) { | ||
cmdutils.AddClusterFlag(fs, cfg.Metadata) | ||
cmdutils.AddRegionFlag(fs, &cmd.ProviderConfig) | ||
cmdutils.AddConfigFileFlag(fs, &cmd.ClusterConfigFile) | ||
fs.BoolVar(&enableZonalShift, "enable-zonal-shift", true, "Enable zonal shift on a cluster") | ||
}) | ||
|
||
} | ||
|
||
func updateZonalShiftConfigCmd(cmd *cmdutils.Cmd) { | ||
updateZonalShiftConfig(cmd, doUpdateZonalShiftConfig) | ||
} | ||
|
||
func doUpdateZonalShiftConfig(cmd *cmdutils.Cmd) error { | ||
cfg := cmd.ClusterConfig | ||
ctx := context.Background() | ||
if cfg.Metadata.Name == "" { | ||
return cmdutils.ErrMustBeSet(cmdutils.ClusterNameFlag(cmd)) | ||
} | ||
ctl, err := cmd.NewProviderForExistingCluster(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
makeZonalShiftStatus := func(enabled *bool) string { | ||
if api.IsEnabled(enabled) { | ||
return "enabled" | ||
} | ||
return "disabled" | ||
} | ||
if zsc := ctl.Status.ClusterInfo.Cluster.ZonalShiftConfig; zsc != nil && *zsc.Enabled == api.IsEnabled(cfg.ZonalShiftConfig.Enabled) { | ||
logger.Info("zonal shift is already %s", makeZonalShiftStatus(zsc.Enabled)) | ||
return nil | ||
} | ||
if err := ctl.UpdateClusterConfig(ctx, &eks.UpdateClusterConfigInput{ | ||
Name: aws.String(cfg.Metadata.Name), | ||
ZonalShiftConfig: &ekstypes.ZonalShiftConfigRequest{ | ||
Enabled: cfg.ZonalShiftConfig.Enabled, | ||
}, | ||
}); err != nil { | ||
return fmt.Errorf("updating zonal shift config: %w", err) | ||
} | ||
logger.Info("zonal shift %s successfully", makeZonalShiftStatus(cfg.ZonalShiftConfig.Enabled)) | ||
return nil | ||
} |
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ | |
Tags: null | ||
Version: null | ||
UpgradePolicy: null | ||
ZonalShiftConfig: null |
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,48 @@ | ||
# Support for Zonal Shift in EKS clusters | ||
|
||
EKS now supports Amazon Application Recovery Controller (ARC) zonal shift and zonal autoshift that enhances the | ||
resiliency of multi-AZ cluster environments. With AWS Zonal Shift, customers can shift in-cluster traffic away | ||
from an impaired availability zone, ensuring new Kubernetes pods and nodes are launched in healthy availability zones only. | ||
|
||
## Creating a cluster with zonal shift enabled | ||
|
||
```yaml | ||
# zonal-shift-cluster.yaml | ||
--- | ||
apiVersion: eksctl.io/v1alpha5 | ||
kind: ClusterConfig | ||
|
||
metadata: | ||
name: highly-available-cluster | ||
region: us-west-2 | ||
|
||
|
||
zonalShiftConfig: | ||
enabled: true | ||
|
||
``` | ||
|
||
```shell | ||
$ eksctl create cluster -f zonal-shift-cluster.yaml | ||
``` | ||
|
||
|
||
## Enabling zonal shift on an existing cluster | ||
|
||
To enable or disable zonal shift on an existing cluster, run | ||
|
||
```shell | ||
$ eksctl utils update-zonal-shift-config -f zonal-shift-cluster.yaml | ||
``` | ||
|
||
or without a config file: | ||
|
||
```shell | ||
$ eksctl utils update-zonal-shift-config --cluster=zonal-shift-cluster --enabled | ||
``` | ||
|
||
## Further information | ||
|
||
- [EKS Zonal Shift][eks-user-guide] | ||
|
||
[eks-user-guide]: https://docs.aws.amazon.com/eks/latest/userguide/zone-shift.html |