Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow updating firewall networks #34

Merged
merged 7 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/metal-stack/metal-lib/auth"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/fi-ts/cloud-go/api/client/cluster"

Expand Down Expand Up @@ -305,6 +306,7 @@ func init() {
clusterUpdateCmd.Flags().BoolP("allowprivileged", "", false, "allow privileged containers the cluster, please add --yes-i-really-mean-it")
clusterUpdateCmd.Flags().String("purpose", "", "purpose of the cluster, can be one of production|development|evaluation. SLA is only given on production clusters.")
clusterUpdateCmd.Flags().StringSlice("egress", []string{}, "static egress ips per network, must be in the form <networkid>:<semicolon-separated ips>; e.g.: --egress internet:1.2.3.4;1.2.3.5 --egress extnet:123.1.1.1 [optional]. Use --egress none to remove all ingress rules.")
clusterUpdateCmd.Flags().StringSlice("external-networks", []string{}, "external networks of the cluster")
clusterUpdateCmd.Flags().Duration("healthtimeout", 0, "period (e.g. \"24h\") after which an unhealthy node is declared failed and will be replaced.")
clusterUpdateCmd.Flags().Duration("draintimeout", 0, "period (e.g. \"3h\") after which a draining node will be forcefully deleted.")

Expand Down Expand Up @@ -692,6 +694,7 @@ func updateCluster(args []string) error {
firewallType := viper.GetString("firewalltype")
firewallImage := viper.GetString("firewallimage")
firewallController := viper.GetString("firewallcontroller")
firewallNetworks := viper.GetStringSlice("external-networks")
machineType := viper.GetString("machinetype")
machineImageAndVersion := viper.GetString("machineimage")
purpose := viper.GetString("purpose")
Expand All @@ -701,10 +704,11 @@ func updateCluster(args []string) error {

findRequest := cluster.NewFindClusterParams()
findRequest.SetID(ci)
current, err := cloud.Cluster.FindCluster(findRequest, nil)
resp, err := cloud.Cluster.FindCluster(findRequest, nil)
if err != nil {
return err
}
current := resp.Payload

healthtimeout := viper.GetDuration("healthtimeout")
draintimeout := viper.GetDuration("draintimeout")
Expand All @@ -715,7 +719,7 @@ func updateCluster(args []string) error {
}

if minsize != 0 || maxsize != 0 || machineImageAndVersion != "" || machineType != "" || healthtimeout != 0 || draintimeout != 0 {
workers := current.Payload.Workers
workers := current.Workers

var worker *models.V1Worker
if workergroupname != "" {
Expand Down Expand Up @@ -760,7 +764,7 @@ func updateCluster(args []string) error {
}

mcmMigrated := false
for _, feature := range current.Payload.ControlPlaneFeatureGates {
for _, feature := range current.ControlPlaneFeatureGates {
if feature == "machineControllerManagerOOT" {
mcmMigrated = true
break
Expand All @@ -784,21 +788,35 @@ func updateCluster(args []string) error {
cur.Workers = append(cur.Workers, workers...)
}

updateCausesDowntime := false
if firewallImage != "" {
if current.FirewallImage != nil && *current.FirewallImage != firewallImage {
updateCausesDowntime = true
}
cur.FirewallImage = &firewallImage
}
if firewallType != "" {
if current.FirewallSize != nil && *current.FirewallSize != firewallType {
updateCausesDowntime = true
}
cur.FirewallSize = &firewallType
}
if firewallController != "" {
cur.FirewallControllerVersion = &firewallController
}
if len(firewallNetworks) > 0 {
if !sets.NewString(firewallNetworks...).Equal(sets.NewString(current.AdditionalNetworks...)) {
updateCausesDowntime = true
}
cur.AdditionalNetworks = firewallNetworks
}

if purpose != "" {
cur.Purpose = &purpose
}

if len(addLabels) > 0 || len(removeLabels) > 0 {
labelMap := current.Payload.Labels
labelMap := current.Labels

for _, l := range removeLabels {
parts := strings.SplitN(l, "=", 2)
Expand Down Expand Up @@ -830,6 +848,14 @@ func updateCluster(args []string) error {

cur.EgressRules = makeEgressRules(egress)

if updateCausesDowntime && !viper.GetBool("yes-i-really-mean-it") {
fmt.Println("This cluster update will cause downtime.")
err = helper.Prompt("Are you sure? (y)", "y")
if err != nil {
return err
}
}

request.SetBody(cur)
shoot, err := cloud.Cluster.UpdateCluster(request, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ipStatic(args []string) error {

if !viper.GetBool("yes-i-really-mean-it") {
fmt.Println("Turning an IP from ephemeral to static is irreversible. The IP address is not cleaned up automatically on cluster deletion. The address will be accounted until the IP address gets freed manually from your side.")
err = helper.Prompt("Are you sure? (y/n)", "y")
err = helper.Prompt("Are you sure? (y)", "y")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing "/n" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it should not be part of this PR. I made an issue why I think there is something problematic about the "no" answer: #52

if err != nil {
return err
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func ipAllocate(args []string) error {

if !viper.GetBool("yes-i-really-mean-it") {
fmt.Println("Allocating a static IP address costs additional money because addresses are limited. The IP address is not cleaned up automatically on cluster deletion. The address will be accounted until the IP address gets freed manually from your side.")
err := helper.Prompt("Are you sure? (y/n)", "y")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

err := helper.Prompt("Are you sure? (y)", "y")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.10.0
github.com/fi-ts/cloud-go v0.12.0
github.com/fi-ts/cloud-go v0.12.1
github.com/gardener/gardener v1.8.2
github.com/ghodss/yaml v1.0.0
github.com/go-openapi/runtime v0.19.26 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/fi-ts/cloud-go v0.12.0 h1:E1af0riAsmfill4ZFWfs3QfI7aW9DFxgO8H0qrOvvFs=
github.com/fi-ts/cloud-go v0.12.0/go.mod h1:6AzwXmDWL4KJk3F+jZwu5fxwPT7qvAvAKDShiu1aMy8=
github.com/fi-ts/cloud-go v0.12.1-0.20210201085152-ec71afbee7af h1:V60L3VTFn3/fWRHNzUN5vBj7mZKcqo563civB0HQlqs=
github.com/fi-ts/cloud-go v0.12.1-0.20210201085152-ec71afbee7af/go.mod h1:6AzwXmDWL4KJk3F+jZwu5fxwPT7qvAvAKDShiu1aMy8=
github.com/frankban/quicktest v1.5.0/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down