@@ -827,6 +827,22 @@ func (c *Cluster) EnforceOutgoingPeeringFlag(ctx context.Context, remoteID *disc
827
827
return nil
828
828
}
829
829
830
+ // EnforceIncomingPeeringFlag sets the incoming peering flag for a given foreign cluster.
831
+ func (c * Cluster ) EnforceIncomingPeeringFlag (ctx context.Context , remoteID * discoveryv1alpha1.ClusterIdentity , enabled bool ) error {
832
+ s := c .local .Printer .StartSpinner (fmt .Sprintf ("configuring the incoming peering flag for the remote cluster %q" , remoteID .ClusterName ))
833
+ if _ , err := controllerutil .CreateOrUpdate (ctx , c .local .CRClient , c .foreignCluster , func () error {
834
+ if enabled {
835
+ c .foreignCluster .Spec .IncomingPeeringEnabled = discoveryv1alpha1 .PeeringEnabledYes
836
+ }
837
+ return nil
838
+ }); err != nil {
839
+ s .Fail (fmt .Sprintf ("an error occurred while configuring the incoming peering flag for remote cluster %q: %v" , remoteID .ClusterName , err ))
840
+ return err
841
+ }
842
+ s .Success (fmt .Sprintf ("incoming peering flag for remote cluster %q correctly configured" , remoteID .ClusterName ))
843
+ return nil
844
+ }
845
+
830
846
// DeleteForeignCluster deletes the foreignclusters instance for the given remote cluster.
831
847
func (c * Cluster ) DeleteForeignCluster (ctx context.Context , remoteClusterID * discoveryv1alpha1.ClusterIdentity ) error {
832
848
remID := remoteClusterID .ClusterID
@@ -861,7 +877,7 @@ func (c *Cluster) DeleteForeignCluster(ctx context.Context, remoteClusterID *dis
861
877
}
862
878
863
879
// DisablePeering disables the peering for the remote cluster by patching the foreigncusters resource.
864
- func (c * Cluster ) DisablePeering (ctx context.Context , remoteClusterID * discoveryv1alpha1.ClusterIdentity ) (err error ) {
880
+ func (c * Cluster ) DisablePeering (ctx context.Context , remoteClusterID * discoveryv1alpha1.ClusterIdentity , incoming bool ) (err error ) {
865
881
remID := remoteClusterID .ClusterID
866
882
remName := remoteClusterID .ClusterName
867
883
s := c .local .Printer .StartSpinner (fmt .Sprintf ("disabling peering for the remote cluster %q" , remName ))
@@ -894,6 +910,18 @@ func (c *Cluster) DisablePeering(ctx context.Context, remoteClusterID *discovery
894
910
remName , fc .Spec .PeeringType , discoveryv1alpha1 .PeeringTypeInBand )
895
911
}
896
912
913
+ // Set incoming peering to no and return if flag is set
914
+ if incoming {
915
+ if _ , err = controllerutil .CreateOrUpdate (ctx , c .local .CRClient , fc , func () error {
916
+ fc .Spec .IncomingPeeringEnabled = "No"
917
+ return nil
918
+ }); err != nil {
919
+ return fmt .Errorf ("an error occurred while disabling incoming peering for remote cluster %q: %w" , remName , err )
920
+ }
921
+ s .Success (fmt .Sprintf ("incoming peering correctly disabled for remote cluster %q" , remName ))
922
+ return nil
923
+ }
924
+
897
925
// Set outgoing peering to no.
898
926
if _ , err = controllerutil .CreateOrUpdate (ctx , c .local .CRClient , fc , func () error {
899
927
fc .Spec .OutgoingPeeringEnabled = "No"
0 commit comments