-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package konnect | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1" | ||
) | ||
|
||
const ( | ||
// IndexFieldKongKeyOnKongKeySetReference is the index field for KongKey-> KongKeySet. | ||
IndexFieldKongKeyOnKongKeySetReference = "kongKeySetRef" | ||
|
||
// IndexFieldKongKeyOnKonnectGatewayControlPlane is the index field for KongKey -> KonnectGatewayControlPlane. | ||
IndexFieldKongKeyOnKonnectGatewayControlPlane = "kongKeyKonnectGatewayControlPlaneRef" | ||
) | ||
|
||
// IndexOptionsForKongKey returns required Index options for KongKey reconclier. | ||
func IndexOptionsForKongKey() []ReconciliationIndexOption { | ||
return []ReconciliationIndexOption{ | ||
{ | ||
IndexObject: &configurationv1alpha1.KongKey{}, | ||
IndexField: IndexFieldKongKeyOnKongKeySetReference, | ||
ExtractValue: kongKeySetRefFromKongKey, | ||
}, | ||
{ | ||
IndexObject: &configurationv1alpha1.KongKey{}, | ||
IndexField: IndexFieldKongKeyOnKonnectGatewayControlPlane, | ||
ExtractValue: konnectGatewayControlPlaneRefFromKongKey, | ||
}, | ||
} | ||
} | ||
|
||
// kongKeySetRefFromKongKey returns namespace/name of referenced KongKeySet in KongKey spec. | ||
func kongKeySetRefFromKongKey(obj client.Object) []string { | ||
key, ok := obj.(*configurationv1alpha1.KongKey) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
if key.Spec.KeySetRef == nil || | ||
key.Spec.KeySetRef.Type != configurationv1alpha1.KeySetRefNamespacedRef || | ||
key.Spec.KeySetRef.NamespacedRef == nil { | ||
return nil | ||
} | ||
|
||
return []string{key.GetNamespace() + "/" + key.Spec.KeySetRef.NamespacedRef.Name} | ||
} | ||
|
||
// kongPluginReferencesFromKongKey returns namespace/name of referenced KonnectGatewayControlPlane in KongKey spec. | ||
func konnectGatewayControlPlaneRefFromKongKey(obj client.Object) []string { | ||
key, ok := obj.(*configurationv1alpha1.KongKey) | ||
if !ok { | ||
return nil | ||
} | ||
return controlPlaneKonnectNamespacedRefAsSlice(key) | ||
} |
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