-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CRD informer list generation to k8s
This is in preparation for adding in filtering by discovered CRD types. Updates #2219 Signed-off-by: Nick Young <ynick@vmware.com>
- Loading branch information
Nick Young
committed
Mar 19, 2020
1 parent
56f7a47
commit 1496df4
Showing
3 changed files
with
75 additions
and
25 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
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,61 @@ | ||
// Copyright © 2020 VMware | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package k8s | ||
|
||
import ( | ||
projectcontour "github.com/projectcontour/contour/apis/projectcontour/v1" | ||
|
||
ingressroutev1 "github.com/projectcontour/contour/apis/contour/v1beta1" | ||
|
||
serviceapis "sigs.k8s.io/service-apis/api/v1alpha1" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic/dynamicinformer" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
type gvrmap map[schema.GroupVersionResource]cache.SharedIndexInformer | ||
|
||
// GVRInformer stores a table of Kubernetes GVR objects to their associated informers. | ||
type GVRInformer struct { | ||
Informers gvrmap | ||
} | ||
|
||
// DefaultGVRInformer creates a new GVRInformer lookup table and populates with the default | ||
// GVRs that Contour will try to watch. | ||
func DefaultGVRInformer(inffactory dynamicinformer.DynamicSharedInformerFactory, serviceAPIs bool) GVRInformer { | ||
|
||
defaultGVRs := []schema.GroupVersionResource{ | ||
ingressroutev1.IngressRouteGVR, | ||
ingressroutev1.TLSCertificateDelegationGVR, | ||
projectcontour.HTTPProxyGVR, | ||
projectcontour.TLSCertificateDelegationGVR, | ||
} | ||
|
||
if serviceAPIs { | ||
defaultGVRs = append(defaultGVRs, serviceapis.GroupVersion.WithResource("gatewayclasses")) | ||
defaultGVRs = append(defaultGVRs, serviceapis.GroupVersion.WithResource("gateways")) | ||
defaultGVRs = append(defaultGVRs, serviceapis.GroupVersion.WithResource("httproutes")) | ||
defaultGVRs = append(defaultGVRs, serviceapis.GroupVersion.WithResource("tcproutes")) | ||
} | ||
|
||
gvri := GVRInformer{ | ||
Informers: make(gvrmap), | ||
} | ||
|
||
for _, gvr := range defaultGVRs { | ||
gvri.Informers[gvr] = inffactory.ForResource(gvr).Informer() | ||
} | ||
return gvri | ||
} |
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