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

Revert PR #17145 #17675

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion clustermesh-apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func runServer(cmd *cobra.Command) {
if err := k8s.Init(k8sconfig.NewDefaultConfiguration()); err != nil {
log.WithError(err).Fatal("Unable to connect to Kubernetes apiserver")
}
synced.SyncCRDs(context.TODO(), synced.AllCRDResourceNames(), &synced.Resources{}, &synced.APIGroups{})
synced.SyncCRDs(context.TODO(), synced.AllCRDResourceNames, &synced.Resources{}, &synced.APIGroups{})
ciliumK8sClient = k8s.CiliumClient()
}

Expand Down
53 changes: 31 additions & 22 deletions pkg/k8s/apis/cilium.io/client/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cilium/cilium/pkg/k8s"
k8sconstv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
k8sconstv2alpha1 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2alpha1"
"github.com/cilium/cilium/pkg/k8s/synced"
k8sversion "github.com/cilium/cilium/pkg/k8s/version"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
Expand Down Expand Up @@ -66,32 +65,42 @@ var (
comparableCRDSchemaVersion = versioncheck.MustVersion(k8sconstv2.CustomResourceDefinitionSchemaVersion)
)

type crdCreationFn func(clientset apiextensionsclient.Interface) error

// CreateCustomResourceDefinitions creates our CRD objects in the Kubernetes
// cluster.
func CreateCustomResourceDefinitions(clientset apiextensionsclient.Interface) error {
g, _ := errgroup.WithContext(context.Background())

resourceToCreateFnMapping := map[string]crdCreationFn{
synced.CRDResourceName(k8sconstv2.CNPName): createCNPCRD,
synced.CRDResourceName(k8sconstv2.CCNPName): createCCNPCRD,
synced.CRDResourceName(k8sconstv2.CNName): createNodeCRD,
synced.CRDResourceName(k8sconstv2.CIDName): createIdentityCRD,
synced.CRDResourceName(k8sconstv2.CEPName): createCEPCRD,
synced.CRDResourceName(k8sconstv2.CEWName): createCEWCRD,
synced.CRDResourceName(k8sconstv2.CLRPName): createCLRPCRD,
synced.CRDResourceName(k8sconstv2alpha1.CENPName): createCENPCRD,
}
for _, r := range synced.OperatorCRDResourceNames() {
fn, ok := resourceToCreateFnMapping[r]
if !ok {
log.Fatalf("Unknown resource %s. Please update pkg/k8s/apis/cilium.io/client to understand this type.", r)
}
g.Go(func() error {
return fn(clientset)
})
}
g.Go(func() error {
return createCNPCRD(clientset)
})

g.Go(func() error {
return createCCNPCRD(clientset)
})

g.Go(func() error {
return createCEPCRD(clientset)
})

g.Go(func() error {
return createNodeCRD(clientset)
})

g.Go(func() error {
return createCEWCRD(clientset)
})

g.Go(func() error {
return createIdentityCRD(clientset)
})

g.Go(func() error {
return createCLRPCRD(clientset)
})

g.Go(func() error {
return createCENPCRD(clientset)
})

return g.Wait()
}
Expand Down
63 changes: 22 additions & 41 deletions pkg/k8s/synced/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,28 @@ const (
k8sAPIGroupCRD = "CustomResourceDefinition"
)

func CRDResourceName(crd string) string {
return "crd:" + crd
}

func agentCRDResourceNames(override bool) []string {
result := []string{
CRDResourceName(v2.CNPName),
CRDResourceName(v2.CCNPName),
CRDResourceName(v2.CNName),
CRDResourceName(v2.CIDName),
}

if override || !option.Config.DisableCiliumEndpointCRD {
result = append(result, CRDResourceName(v2.CEPName))
}
if override || option.Config.EnableEgressGateway {
result = append(result, CRDResourceName(v2alpha1.CENPName))
var (
// AgentCRDResourceNames is a list of all CRD resource names
// the Cilium agent needs to wait to be registered before
// initializing any k8s watchers.
AgentCRDResourceNames = []string{
crdResourceName(v2.CNPName),
crdResourceName(v2.CCNPName),
crdResourceName(v2.CEPName),
crdResourceName(v2.CNName),
crdResourceName(v2.CIDName),
crdResourceName(v2.CLRPName),
crdResourceName(v2alpha1.CENPName),
}
if override || option.Config.EnableLocalRedirectPolicy {
result = append(result, CRDResourceName(v2.CLRPName))
}

return result
}

// AgentCRDResourceNames returns a list of all CRD resource names the Cilium
// agent needs to wait to be registered before initializing any k8s watchers.
func AgentCRDResourceNames() []string {
return agentCRDResourceNames(false)
}

// OperatorCRDResourceNames returns a list of all CRD resource names that the
// operator may register.
func OperatorCRDResourceNames() []string {
return append(agentCRDResourceNames(false), CRDResourceName(v2.CEWName))
}
// AllCRDResourceNames is a list of all CRD resource names
// Cilium Operator is registering.
AllCRDResourceNames = append([]string{
crdResourceName(v2.CEWName),
}, AgentCRDResourceNames...)
)

// AllCRDResourceNames returns a list of all CRD resource names that the
// clustermesh-apiserver or testsuite may register.
func AllCRDResourceNames() []string {
return append(agentCRDResourceNames(true), CRDResourceName(v2.CEWName))
func crdResourceName(crd string) string {
return "crd:" + crd
}

// SyncCRDs will sync Cilium CRDs to ensure that they have all been
Expand Down Expand Up @@ -173,15 +154,15 @@ func SyncCRDs(ctx context.Context, crdNames []string, rs *Resources, ag *APIGrou
func (s *crdState) add(obj interface{}) {
if pom := k8s.ObjToV1PartialObjectMetadata(obj); pom != nil {
s.Lock()
s.m[CRDResourceName(pom.GetName())] = true
s.m[crdResourceName(pom.GetName())] = true
s.Unlock()
}
}

func (s *crdState) remove(obj interface{}) {
if pom := k8s.ObjToV1PartialObjectMetadata(obj); pom != nil {
s.Lock()
s.m[CRDResourceName(pom.GetName())] = false
s.m[crdResourceName(pom.GetName())] = false
s.Unlock()
}
}
Expand Down
20 changes: 0 additions & 20 deletions pkg/k8s/watchers/endpoint_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/cilium/cilium/pkg/option"

v1 "k8s.io/api/core/v1"
v1meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -169,22 +168,3 @@ func (k *K8sWatcher) updateK8sEndpointSliceV1Beta1(eps *slim_discover_v1beta1.En
k.bgpSpeakerManager.OnUpdateEndpointSliceV1Beta1(eps)
}
}

// initEndpointsOrSlices initializes either the "Endpoints" or "EndpointSlice"
// resources for Kubernetes service backends.
func (k *K8sWatcher) initEndpointsOrSlices(k8sClient kubernetes.Interface, serviceOptModifier func(*v1meta.ListOptions)) {
swgEps := lock.NewStoppableWaitGroup()
switch {
case k8s.SupportsEndpointSlice():
// We don't add the service option modifier here, as endpointslices do not
// mirror service proxy name label present in the corresponding service.
connected := k.endpointSlicesInit(k8sClient, swgEps)
// The cluster has endpoint slices so we should not check for v1.Endpoints
if connected {
break
}
fallthrough
default:
k.endpointsInit(k8sClient, swgEps, serviceOptModifier)
}
}