-
Notifications
You must be signed in to change notification settings - Fork 16
Allow egress ips on managedseeds #207
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
Open
modzilla99
wants to merge
2
commits into
stackitcloud:main
Choose a base branch
from
modzilla99:allow-egress-ips-on-managedseeds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import ( | |
| "github.com/pkg/errors" | ||
| istionetworkv1beta1 "istio.io/client-go/pkg/apis/networking/v1beta1" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/serializer" | ||
| "k8s.io/client-go/rest" | ||
|
|
@@ -48,6 +49,8 @@ import ( | |
| "github.com/stackitcloud/gardener-extension-acl/pkg/extensionspec" | ||
| "github.com/stackitcloud/gardener-extension-acl/pkg/helper" | ||
| "github.com/stackitcloud/gardener-extension-acl/pkg/imagevector" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -87,13 +90,15 @@ func NewActuator(mgr manager.Manager, cfg config.Config) extension.Actuator { | |
| return &actuator{ | ||
| extensionConfig: cfg, | ||
| client: mgr.GetClient(), | ||
| reader: mgr.GetAPIReader(), | ||
| config: mgr.GetConfig(), | ||
| decoder: serializer.NewCodecFactory(mgr.GetScheme(), serializer.EnableStrict).UniversalDecoder(), | ||
| } | ||
| } | ||
|
|
||
| type actuator struct { | ||
| client client.Client | ||
| reader client.Reader | ||
| config *rest.Config | ||
| decoder runtime.Decoder | ||
| extensionConfig config.Config | ||
|
|
@@ -147,6 +152,18 @@ func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, ex *extension | |
|
|
||
| alwaysAllowedCIDRs = append(alwaysAllowedCIDRs, helper.GetSeedSpecificAllowedCIDRs(cluster.Seed)...) | ||
|
|
||
| // In casese where the istio-ingressgateway is exposed with the Proxy IPMode some | ||
| // CNIs (like cilium for example) do not hairpin NAT the traffic to it, which | ||
| // will result in the destination IP being set to the egressIP of the cluster. | ||
| // In that case the AlertManager ApiServerNoteReachable check will fail. | ||
| if a.usesProxyTypeLBService(ctx, log, istioLabels) { | ||
| egressCIDRs, err := a.getSeedEgressIPOnManagedSeeds(ctx) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| alwaysAllowedCIDRs = append(alwaysAllowedCIDRs, egressCIDRs...) | ||
| } | ||
|
|
||
| if len(a.extensionConfig.AdditionalAllowedCIDRs) >= 1 { | ||
| alwaysAllowedCIDRs = append(alwaysAllowedCIDRs, a.extensionConfig.AdditionalAllowedCIDRs...) | ||
| } | ||
|
|
@@ -260,14 +277,14 @@ func (a *actuator) createSeedResources( | |
| spec *extensionspec.ExtensionSpec, | ||
| cluster *controller.Cluster, | ||
| hosts []string, | ||
| shootSpecificCIRDs []string, | ||
| shootSpecificCIDRs []string, | ||
| alwaysAllowedCIDRs []string, | ||
| istioNamespace string, | ||
| istioLabels map[string]string, | ||
| ) error { | ||
| var err error | ||
|
|
||
| alwaysAllowedCIDRs = append(alwaysAllowedCIDRs, shootSpecificCIRDs...) | ||
| alwaysAllowedCIDRs = append(alwaysAllowedCIDRs, shootSpecificCIDRs...) | ||
|
|
||
| apiEnvoyFilterSpec, err := envoyfilters.BuildAPIEnvoyFilterSpecForHelmChart( | ||
| spec.Rule, hosts, alwaysAllowedCIDRs, istioLabels, | ||
|
|
@@ -446,3 +463,68 @@ func (a *actuator) findDefaultIstioLabels( | |
|
|
||
| return gw.Spec.Selector, nil | ||
| } | ||
|
|
||
| // usesProxyTypeLBService checks the `istio-ingressgateway` LoadBalancer Service | ||
| // selected by its labels whether it is exposing the service with the Proxy IPMode | ||
| func (a *actuator) usesProxyTypeLBService( | ||
| ctx context.Context, | ||
| log logr.Logger, | ||
| labels map[string]string, | ||
| ) bool { | ||
| svcs := corev1.ServiceList{} | ||
| labelsSelector := client.MatchingLabels(labels) | ||
| fieldSelector := client.MatchingFields{"metadata.name": v1beta1constants.DefaultSNIIngressServiceName} | ||
| err := a.reader.List(ctx, &svcs, labelsSelector, fieldSelector) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a list with field selector metadata.name and not a simple Get? |
||
| if err != nil { | ||
| log.Error(err, "unable to fetch Services for Istio Ingressgateways", "labels", labels) | ||
| return false | ||
| } | ||
|
|
||
| switch len(svcs.Items) { | ||
| case 1: | ||
| for _, ing := range svcs.Items[0].Status.LoadBalancer.Ingress { | ||
| if m := ing.IPMode; m != nil && *m == corev1.LoadBalancerIPModeProxy { | ||
| return true | ||
| } | ||
| } | ||
| case 0: | ||
| log.Error(nil, "unable to find Istio Ingressgateway service", "name", v1beta1constants.DefaultSNIIngressServiceName, "labels", labels) | ||
| default: | ||
| log.Error(nil, "found more than one IngressGateway service", "name", v1beta1constants.DefaultSNIIngressServiceName, "labels", labels) | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // getSeedEgressIPOnManagedSeeds returns the egressIP CIDRs of the ManagedSeed, if the | ||
| // Seed is not a shoot, it will return an empty list | ||
| func (a *actuator) getSeedEgressIPOnManagedSeeds(ctx context.Context) ([]string, error) { | ||
| cm := corev1.ConfigMap{} | ||
| if err := a.client.Get(ctx, | ||
| client.ObjectKey{ | ||
| Name: v1beta1constants.ConfigMapNameShootInfo, | ||
| Namespace: "kube-system", | ||
| }, | ||
| &cm); err != nil { | ||
| if apierrors.IsNotFound(err) { | ||
| return []string{}, nil | ||
| } | ||
| return nil, err | ||
| } | ||
|
|
||
| cidrsStr, ok := cm.Data["egressCIDRs"] | ||
| if !ok { | ||
| return nil, errors.New("unable to get egress CIDRs from shoot-info ConfigMap") | ||
| } | ||
|
|
||
| var cidrs []string | ||
| for i := range strings.SplitSeq(cidrsStr, ",") { | ||
| _, _, err := net.ParseCIDR(i) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| cidrs = append(cidrs, i) | ||
| } | ||
|
|
||
| return cidrs, nil | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not cover support for ExposureClasses as they use a different service name. Please add support for that.