@@ -3,6 +3,7 @@ package provider
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "sort"
89 "strconv"
@@ -495,6 +496,10 @@ func (p *Provider) listUsers(ctx context.Context, rawAppsMap map[string][]*appv1
495496 if err != nil {
496497 return nil , err
497498 }
499+ masterNodeCIDR , err := p .getMasterNodeCIDR (ctx )
500+ if err != nil {
501+ return nil , err
502+ }
498503
499504 info := & message.UserInfo {
500505 Name : user .Name ,
@@ -514,6 +519,7 @@ func (p *Provider) listUsers(ctx context.Context, rawAppsMap map[string][]*appv1
514519 SSL : sslConfig ,
515520 CustomDomainCerts : allCerts [user .Name ],
516521 FileserverNodes : fileserverNodes ,
522+ MasterNodeCIDR : masterNodeCIDR ,
517523 }
518524 result = append (result , info )
519525 }
@@ -674,6 +680,28 @@ func (p *Provider) getUsers(ctx context.Context) ([]iamv1alpha2.User, error) {
674680 return users , nil
675681}
676682
683+ func (p * Provider ) getMasterNodeCIDR (ctx context.Context ) (string , error ) {
684+ var nodeList corev1.NodeList
685+ if err := p .cache .List (ctx , & nodeList , client.HasLabels {"node-role.kubernetes.io/control-plane" }); err != nil {
686+ klog .Errorf ("provider: list node failed: %v" , err )
687+ return "" , err
688+ }
689+ if len (nodeList .Items ) == 0 {
690+ return "" , errors .New ("no master node found" )
691+ }
692+ node := nodeList .Items [0 ]
693+ if len (node .Annotations ) == 0 {
694+ klog .Warningf ("provider: node %s with empty annotations" , node .Name )
695+ return "" , nil
696+ }
697+ cidr , ok := node .Annotations ["projectcalico.org/IPv4Address" ]
698+ if ! ok {
699+ klog .Warningf ("provider: node %s has no projectcalico.org/IPv4Address annotation" , node .Name )
700+ return "" , nil
701+ }
702+ return cidr , nil
703+ }
704+
677705func getAnnotation (user * iamv1alpha2.User , key string ) string {
678706 if v , ok := user .Annotations [key ]; ok && v != "" {
679707 return v
0 commit comments