-
Notifications
You must be signed in to change notification settings - Fork 89
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
OSSM-1420 Ensure istiod can run with no cluster-scoped privileges #513
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,12 @@ import ( | |
"fmt" | ||
"strings" | ||
"text/template" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/types" | ||
appsinformersv1 "k8s.io/client-go/informers/apps/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/util/workqueue" | ||
gateway "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
"sigs.k8s.io/yaml" | ||
|
@@ -91,14 +86,8 @@ func NewDeploymentController(client kube.Client) *DeploymentController { | |
AddEventHandler(handler) | ||
|
||
// For Deployments, this is the only controller watching. We can filter to just the deployments we care about | ||
client.KubeInformer().InformerFor(&appsv1.Deployment{}, func(k kubernetes.Interface, resync time.Duration) cache.SharedIndexInformer { | ||
return appsinformersv1.NewFilteredDeploymentInformer( | ||
k, metav1.NamespaceAll, resync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, | ||
func(options *metav1.ListOptions) { | ||
options.LabelSelector = "gateway.istio.io/managed=istio.io-gateway-controller" | ||
}, | ||
) | ||
}).AddEventHandler(handler) | ||
// TODO: filter deployments with label selector "gateway.istio.io/managed=istio.io-gateway-controller" | ||
client.KubeInformer().Apps().V1().Deployments().Informer().AddEventHandler(handler) | ||
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. we could consider using 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. AFAICT, the NewFilteredSecretInformer is a more low-level function. If we were to use it, we'd have to keep the list of namespaces in sync using the SMMR controller. On the other hand, this filter here is only used for optimization. |
||
|
||
// Use the full informer; we are already watching all Gateways for the core Istiod logic | ||
client.GatewayAPIInformer().Gateway().V1alpha2().Gateways().Informer(). | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,8 @@ import ( | |
authorizationv1 "k8s.io/api/authorization/v1" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
informersv1 "k8s.io/client-go/informers/core/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/fake" | ||
authorizationv1client "k8s.io/client-go/kubernetes/typed/authorization/v1" | ||
listersv1 "k8s.io/client-go/listers/core/v1" | ||
|
@@ -81,23 +79,7 @@ type authorizationResponse struct { | |
var _ credentials.Controller = &CredentialsController{} | ||
|
||
func NewCredentialsController(client kube.Client, clusterID cluster.ID) *CredentialsController { | ||
informer := client.KubeInformer().InformerFor(&v1.Secret{}, func(k kubernetes.Interface, resync time.Duration) cache.SharedIndexInformer { | ||
return informersv1.NewFilteredSecretInformer( | ||
k, metav1.NamespaceAll, resync, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, | ||
func(options *metav1.ListOptions) { | ||
// We only care about TLS certificates. Unfortunately, it is not as simple as selecting type=kubernetes.io/tls. | ||
// Because of legacy reasons and supporting an extra ca.crt, we also support generic types. | ||
// Its also likely users have started to use random types and expect them to continue working. | ||
// This makes the assumption we will never care about Helm secrets or SA token secrets - two common | ||
// large Secrets in clusters. | ||
// This is a best effort optimization only; the code would behave correctly if we watched all Secrets. | ||
options.FieldSelector = fields.AndSelectors( | ||
fields.OneTermNotEqualSelector("type", "helm.sh/release.v1"), | ||
fields.OneTermNotEqualSelector("type", string(v1.SecretTypeServiceAccountToken)), | ||
).String() | ||
}, | ||
) | ||
}) | ||
informer := client.KubeInformer().Core().V1().Secrets().Informer() | ||
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. same here, we could use NewFilteredSecretInformer(). let's create a follow-up ticket 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. Here, the filtering is only done as a best-effort optimization (according to the comment, the code behaves correctly without it). And since we're only watching the secrets in member namespaces, whereas the upstream code uses a cluster-scoped watch, this optimization may not do much at all. |
||
|
||
return &CredentialsController{ | ||
secrets: informerAdapter{listersv1.NewSecretLister(informer.GetIndexer()), informer}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
"k8s.io/apimachinery/pkg/util/sets" | ||
listerv1 "k8s.io/client-go/listers/core/v1" | ||
|
||
memberroll "istio.io/istio/pkg/servicemesh/controller" | ||
"istio.io/pkg/log" | ||
) | ||
|
||
|
@@ -202,3 +203,51 @@ func (d *discoveryNamespacesFilter) isSelected(labels labels.Set) bool { | |
|
||
return false | ||
} | ||
|
||
type maistraDiscoveryNamespacesFilter struct { | ||
lock sync.RWMutex | ||
namespaces sets.String | ||
} | ||
|
||
func NewMaistraDiscoveryNamespacesFilter(mrc memberroll.MemberRollController) DiscoveryNamespacesFilter { | ||
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. matches exactly what I have :) just called it |
||
d := &maistraDiscoveryNamespacesFilter{} | ||
mrc.Register(d, "MaistraDiscoveryNamespacesFilter") | ||
return d | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) SetNamespaces(namespaces ...string) { | ||
d.lock.Lock() | ||
defer d.lock.Unlock() | ||
d.namespaces = sets.NewString(namespaces...) | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) Filter(obj interface{}) bool { | ||
d.lock.RLock() | ||
defer d.lock.RUnlock() | ||
return d.namespaces.Has(obj.(metav1.Object).GetNamespace()) | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) SelectorsChanged( | ||
discoverySelectors []*metav1.LabelSelector) (selectedNamespaces []string, deselectedNamespaces []string) { | ||
panic("Not implemented") | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) NamespaceCreated(ns metav1.ObjectMeta) (membershipChanged bool) { | ||
panic("Not implemented") | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) NamespaceUpdated(oldNs, newNs metav1.ObjectMeta) (membershipChanged bool, namespaceAdded bool) { | ||
panic("Not implemented") | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) NamespaceDeleted(ns metav1.ObjectMeta) (membershipChanged bool) { | ||
panic("Not implemented") | ||
} | ||
|
||
func (d *maistraDiscoveryNamespacesFilter) GetMembers() sets.String { | ||
d.lock.RLock() | ||
defer d.lock.RUnlock() | ||
members := sets.NewString() | ||
members.Insert(d.namespaces.List()...) | ||
return members | ||
} |
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.
Worth to create a Jira and link it here? We might thinks this is a TODO from upstream and never look back here
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.
I've created OSSM-1448, but I have the feeling that this is something that we'll never actually implement. We'll either move away from xns-informers or upstream will remove the label selector.