Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support isolated clusters #278

Merged
merged 17 commits into from
Feb 1, 2024
8 changes: 4 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false
Expand Down Expand Up @@ -54,10 +54,10 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

Expand Down
42 changes: 42 additions & 0 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func newClusterCmd(c *config) *cobra.Command {
clusterCreateCmd.Flags().BoolP("disable-forwarding-to-upstream-dns", "", false, "disables direct forwarding of queries to external dns servers when node-local-dns is enabled. All dns queries will go through coredns. [optional].")
clusterCreateCmd.Flags().StringSlice("kube-apiserver-acl-allowed-cidrs", []string{}, "comma-separated list of external CIDRs allowed to connect to the kube-apiserver (e.g. \"212.34.68.0/24,212.34.89.0/27\")")
clusterCreateCmd.Flags().Bool("enable-kube-apiserver-acl", false, "restricts access from outside to the kube-apiserver to the source ip addresses set by --kube-apiserver-acl-allowed-cidrs [optional].")
clusterCreateCmd.Flags().String("network-isolation", "", "defines restrictions to external network communication for the cluster, can be one of baseline|restricted|isolated. baseline sets no special restrictions to external networks, restricted by default only allows external traffic to explicitly allowed destinations, forbidden disallows communication with external networks except for a limited set of networks. Please consult the documentation for detailed descriptions of the individual modes as these cannot be altered anymore after creation. [optional]")

must(clusterCreateCmd.MarkFlagRequired("name"))
must(clusterCreateCmd.MarkFlagRequired("project"))
Expand All @@ -288,6 +289,13 @@ func newClusterCmd(c *config) *cobra.Command {
"cilium\tcilium networking plugin. please note that cilium support is still Alpha and we are happy to receive feedback.",
}, cobra.ShellCompDirectiveNoFileComp
}))
must(clusterCreateCmd.RegisterFlagCompletionFunc("network-isolation", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{
models.V1ClusterCreateRequestNetworkAccessTypeBaseline + "\tno special restrictions for external network traffic, service type loadbalancer possible in all networks",
models.V1ClusterCreateRequestNetworkAccessTypeRestricted + "\texternal network traffic needs to be allowed explicitly, own cluster wide network policies possible, service type loadbalancer possible in all networks",
models.V1ClusterCreateRequestNetworkAccessTypeForbidden + "\texternal network traffic is not possible except for allowed networks , own cluster wide network policies not possible, service type loadbalancer possible only in allowed networks, for the allowed networks please see cluster inputs",
}, cobra.ShellCompDirectiveNoFileComp
}))

clusterDescribeCmd.Flags().Bool("no-machines", false, "does not return in the output")

Expand Down Expand Up @@ -487,6 +495,39 @@ func (c *config) clusterCreate() error {
disablePodSecurityPolicies = pointer.Pointer(viper.GetBool("disable-pod-security-policies"))
}

var networkAccessType *string
if viper.IsSet("network-isolation") {
networkAccessType = pointer.Pointer(viper.GetString("network-isolation"))
switch *networkAccessType {
case models.V1ClusterCreateRequestNetworkAccessTypeForbidden:
fmt.Printf(`
WARNING: You are going to create a cluster which has no internet access with the following consequences:
- pulling images is only possible from private registries you provide, these registries must be resolvable from the public dns, their IP must be located in one of the allowed networks (see cluster inputs), and must be secured with a trusted TLS certificate
- service type loadbalancer can only be created in networks which are specified in the allowed networks (see cluster inputs)
- cluster wide network policies can only be created in certain network ranges which are specified in the allowed networks (see cluster inputs)
- It is not possible to change this cluster back to %q after creation
`, models.V1ClusterCreateRequestNetworkAccessTypeBaseline)
err := helper.Prompt("Are you sure? (y/n)", "y")
if err != nil {
return err
}
case models.V1ClusterCreateRequestNetworkAccessTypeRestricted:
fmt.Printf(`
WARNING: You are going to create a cluster that has no default internet access with the following consequences:
- pulling images is only possible from private registries you provide, these registries must be resolvable from the public dns and must be secured with a trusted TLS certificate
- you can create cluster wide network policies to the outside world without restrictions
- pulling container images from registries requires to create a corresponding CWNP to these registries
- It is not possible to change this cluster back to %q after creation
`, models.V1ClusterCreateRequestNetworkAccessTypeBaseline)
err := helper.Prompt("Are you sure? (y/n)", "y")
if err != nil {
return err
}
case models.V1ClusterCreateRequestNetworkAccessTypeBaseline:
// Noop
}
}

labels := viper.GetStringSlice("labels")

// FIXME helper and validation
Expand Down Expand Up @@ -597,6 +638,7 @@ func (c *config) clusterCreate() error {
},
CustomDefaultStorageClass: customDefaultStorageClass,
Cni: cni,
NetworkAccessType: networkAccessType,
}

if viper.IsSet("autoupdate-kubernetes") || viper.IsSet("autoupdate-machineimages") || purpose == string(v1beta1.ShootPurposeEvaluation) {
Expand Down
13 changes: 12 additions & 1 deletion cmd/output/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"os"
"text/template"

"github.com/Masterminds/sprig/v3"
"github.com/fatih/color"
"github.com/fi-ts/cloud-go/api/client/cluster"
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/pkg/api"
sprig "github.com/go-task/slim-sprig/v3"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/spf13/viper"

Expand Down Expand Up @@ -169,6 +170,16 @@ func newPrinter(format, order, tpl string, noHeaders bool, writer io.Writer) (Pr
default:
return nil, fmt.Errorf("unknown format:%s", format)
}

if viper.IsSet("force-color") {
enabled := viper.GetBool("force-color")
if enabled {
color.NoColor = false
} else {
color.NoColor = true
}
}

return printer, nil
}

Expand Down
16 changes: 13 additions & 3 deletions cmd/output/shootprinter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/fatih/color"
"github.com/fi-ts/cloud-go/api/models"
"github.com/fi-ts/cloudctl/cmd/helper"
"github.com/gardener/gardener/pkg/apis/core/v1beta1"
Expand Down Expand Up @@ -147,9 +148,18 @@ func (s ShootIssuesTablePrinter) Print(data []*models.V1ClusterResponse) {

func shootData(shoot *models.V1ClusterResponse, withIssues bool) ([]string, []string, []string) {
shootStats := newShootStats(shoot.Status)
if (*shoot).KubeAPIServerACL != nil && !*shoot.KubeAPIServerACL.Disabled {
if shoot.KubeAPIServerACL != nil && !*shoot.KubeAPIServerACL.Disabled {
shootStats.apiServer += "🔒"
}
name := *shoot.Name
if shoot.NetworkAccessType != nil {
if *shoot.NetworkAccessType == models.V1ClusterCreateRequestNetworkAccessTypeForbidden {
name = color.RedString(name)
}
if *shoot.NetworkAccessType == models.V1ClusterCreateRequestNetworkAccessTypeRestricted {
name = color.YellowString(name)
}
}

maintainEmoji := ""
var issues []string
Expand Down Expand Up @@ -312,7 +322,7 @@ func shootData(shoot *models.V1ClusterResponse, withIssues bool) ([]string, []st

wide := []string{
*shoot.ID,
*shoot.Name,
name,
version, partition, seed, dnsdomain,
operation,
progress,
Expand All @@ -334,7 +344,7 @@ func shootData(shoot *models.V1ClusterResponse, withIssues bool) ([]string, []st
*shoot.ID,
tenant,
project,
*shoot.Name,
name,
version, partition,
operation,
progress,
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func newRootCmd() *cobra.Command {
rootCmd.PersistentFlags().StringP("order", "", "", "order by (comma separated) column(s)")
rootCmd.PersistentFlags().BoolP("no-headers", "", false, "ommit headers in tables")
rootCmd.PersistentFlags().BoolP("debug", "", false, "enable debug")
rootCmd.PersistentFlags().Bool("force-color", false, "force colored output even without tty")
rootCmd.PersistentFlags().StringP("output-format", "o", "table", "output format (table|wide|markdown|json|yaml|template), wide is a table with more columns.")
rootCmd.PersistentFlags().StringP("template", "", "", `output template for template output-format, go template format.
For property names inspect the output of -o json for reference.
Expand Down
81 changes: 37 additions & 44 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,38 @@ go 1.21

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/Masterminds/sprig/v3 v3.2.3
github.com/dcorbe/termui-dpc v0.0.0-20211125210512-9d2673a82dd6
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.16.0
github.com/fi-ts/accounting-go v0.9.0
github.com/fi-ts/cloud-go v0.23.2
github.com/fi-ts/accounting-go v0.9.1
github.com/fi-ts/cloud-go v0.24.3
github.com/gardener/gardener v1.73.2
github.com/gardener/machine-controller-manager v0.50.1
github.com/go-openapi/runtime v0.27.0
github.com/go-openapi/runtime v0.27.1
github.com/go-openapi/strfmt v0.22.0
github.com/go-playground/validator/v10 v10.16.0
github.com/go-playground/validator/v10 v10.17.0
github.com/go-task/slim-sprig/v3 v3.0.0
github.com/google/go-cmp v0.6.0
github.com/gosimple/slug v1.13.1
github.com/jinzhu/now v1.1.5
github.com/metal-stack/duros-go v0.4.3
github.com/metal-stack/duros-go v0.4.4
github.com/metal-stack/metal-go v0.26.3
github.com/metal-stack/metal-lib v0.14.3
github.com/metal-stack/metal-lib v0.14.4
github.com/metal-stack/updater v1.2.1
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.5.0
golang.org/x/sync v0.6.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.28.2
k8s.io/apimachinery v0.28.2
sigs.k8s.io/yaml v1.4.0
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/akutz/memconn v0.1.0 // indirect
Expand All @@ -59,10 +58,10 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.4 // indirect
github.com/coreos/go-iptables v0.7.0 // indirect
github.com/coreos/go-oidc/v3 v3.8.0 // indirect
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dblohm7/wingoes v0.0.0-20230929194252-e994401fc077 // indirect
github.com/dblohm7/wingoes v0.0.0-20231220174005-6310b4cece37 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e // indirect
github.com/emicklei/go-restful-openapi/v2 v2.9.1 // indirect
Expand All @@ -71,21 +70,21 @@ require (
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/analysis v0.22.0 // indirect
github.com/go-openapi/analysis v0.22.2 // indirect
github.com/go-openapi/errors v0.21.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/loads v0.21.5 // indirect
github.com/go-openapi/spec v0.20.13 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/go-openapi/spec v0.20.14 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-openapi/validate v0.22.6 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-yaml v1.11.2 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
Expand All @@ -96,27 +95,25 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/csrf v1.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/csrf v1.7.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230908212754-65c27093e38a // indirect
github.com/insomniacslk/dhcp v0.0.0-20231206064809-8c70d406f6d2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.3.5 // indirect
github.com/jsimonetti/rtnetlink v1.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jszwec/csvutil v1.8.0 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/jszwec/csvutil v1.9.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
Expand All @@ -135,27 +132,23 @@ require (
github.com/mdlayher/sdnotify v1.0.0 // indirect
github.com/mdlayher/socket v0.5.0 // indirect
github.com/metal-stack/security v0.7.1 // indirect
github.com/miekg/dns v1.1.56 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/miekg/dns v1.1.57 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nsf/termbox-go v1.1.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/safchain/ethtool v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -168,7 +161,7 @@ require (
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tailscale/web-client-prebuilt v0.0.0-20231114171715-25f8d12b3c2d // indirect
github.com/tailscale/web-client-prebuilt v0.0.0-20231201220427-3a45625fe806 // indirect
github.com/tailscale/wireguard-go v0.0.0-20231101022006-db7604d1aa90 // indirect
github.com/tcnksm/go-httpstat v0.2.0 // indirect
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
Expand All @@ -182,34 +175,34 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20230824141953-6213f710f925 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.0 // indirect
golang.org/x/tools v0.17.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 // indirect
google.golang.org/grpc v1.60.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gvisor.dev/gvisor v0.0.0-20230928000133-4fe30062272c // indirect
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
nhooyr.io/websocket v1.8.7 // indirect
nhooyr.io/websocket v1.8.10 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
tailscale.com v1.54.0 // indirect
Expand Down
Loading
Loading