@@ -46,6 +46,9 @@ const (
4646 BuildkitProxyPath = "buildkit/" + proxyDir
4747)
4848
49+ var ErrBuildxNodeGroupNotFound = errors .New ("buildx node group not found" )
50+ var ErrIsNotRemoteDriver = errors .New ("buildx node group does not have 'remote' driver" )
51+
4952func newSetupBuildxCmd () * cobra.Command {
5053 cmd := & cobra.Command {
5154 Use : "setup" ,
@@ -503,34 +506,23 @@ type ServerProxyEndpoint struct {
503506 Endpoint string
504507}
505508
506- func getServerSideProxyEndpoints (txn * store.Txn , name string ) []ServerProxyEndpoint {
507- var endpoints []ServerProxyEndpoint
509+ func isNamespaceBuildkitEndpoint (endpoint string ) bool {
510+ return strings .Contains (endpoint , "namespaceapis.com" )
511+ }
508512
509- ng , err := txn .NodeGroupByName (name )
513+ func isServerSideProxy (txn * store.Txn , name string ) bool {
514+ configs , err := readRemoteBuilderConfigsTxn (txn , name )
510515 if err != nil {
511- return endpoints
516+ return false
512517 }
513518
514- if ng .Driver != "remote" {
515- return endpoints
516- }
517-
518- for _ , node := range ng .Nodes {
519- for _ , plat := range node .Platforms {
520- if strings .Contains (node .Endpoint , "namespaceapis.com" ) {
521- endpoints = append (endpoints , ServerProxyEndpoint {
522- Platform : plat .OS + "/" + plat .Architecture ,
523- Endpoint : node .Endpoint ,
524- })
525- }
519+ for _ , cfg := range configs {
520+ if isNamespaceBuildkitEndpoint (cfg .FullBuildkitEndpoint ) {
521+ return true
526522 }
527523 }
528524
529- return endpoints
530- }
531-
532- func isServerSideProxy (txn * store.Txn , name string ) bool {
533- return len (getServerSideProxyEndpoints (txn , name )) != 0
525+ return false
534526}
535527
536528func doClientSideProxyCleanup (ctx context.Context , state string , txn * store.Txn ) error {
@@ -731,7 +723,7 @@ func newStatusBuildxCommand() *cobra.Command {
731723 return err
732724 }
733725
734- sspDescs , err := determineServerSideProxyConfig ( dockerCli , * name )
726+ sspDescs , err := determineServerSideProxyStatus ( ctx , dockerCli , * name )
735727 if err != nil {
736728 return err
737729 }
@@ -765,12 +757,20 @@ func newStatusBuildxCommand() *cobra.Command {
765757 for _ , desc := range descs {
766758 fmt .Fprintf (stdout , "Platform: %s\n " , desc .Platform )
767759 fmt .Fprintf (stdout , " Status: %s\n " , desc .Status )
768- fmt .Fprintf (stdout , " Last Instance ID: %s\n " , desc .LastInstanceID )
769- fmt .Fprintf (stdout , " Last Update: %v\n " , desc .LastUpdate )
770- fmt .Fprintf (stdout , " Last Error: %v\n " , desc .LastError )
771- fmt .Fprintf (stdout , " Requests Handled: %v\n " , desc .Requests )
772- fmt .Fprintf (stdout , " Log Path: %v\n " , desc .LogPath )
773- fmt .Fprintf (stdout , "\n " )
760+ if desc .IsServerSideProxy {
761+ if desc .LastError == "" {
762+ fmt .Fprintf (stdout , " Connectivity check successful\n " )
763+ } else {
764+ fmt .Fprintf (stdout , " Connectivity error: %s\n " , desc .LastError )
765+ }
766+ } else {
767+ fmt .Fprintf (stdout , " Last Instance ID: %s\n " , desc .LastInstanceID )
768+ fmt .Fprintf (stdout , " Last Error: %v\n " , desc .LastError )
769+ fmt .Fprintf (stdout , " Last Update: %v\n " , desc .LastUpdate )
770+ fmt .Fprintf (stdout , " Requests Handled: %v\n " , desc .Requests )
771+ fmt .Fprintf (stdout , " Log Path: %v\n " , desc .LogPath )
772+ fmt .Fprintf (stdout , "\n " )
773+ }
774774 }
775775 }
776776
@@ -780,21 +780,90 @@ func newStatusBuildxCommand() *cobra.Command {
780780 return cmd
781781}
782782
783- func determineServerSideProxyConfig (dockerCli * command.DockerCli , name string ) ([]StatusData , error ) {
784- descs := []StatusData {}
783+ func readRemoteBuilderConfigs (dockerCli * command.DockerCli , name string ) ([]BuilderConfig , error ) {
784+ var res []BuilderConfig
785785
786786 err := withStore (dockerCli , func (txn * store.Txn ) error {
787- endpoints := getServerSideProxyEndpoints (txn , name )
788- for _ , e := range endpoints {
789- descs = append (descs , StatusData {
790- Platform : e .Platform ,
791- Status : ProxyStatus_ServerSide ,
792- })
787+ r , err := readRemoteBuilderConfigsTxn (txn , name )
788+ if err != nil {
789+ return err
793790 }
794791
792+ res = r
795793 return nil
796794 })
797795
796+ return res , err
797+ }
798+
799+ func readRemoteBuilderConfigsTxn (txn * store.Txn , name string ) ([]BuilderConfig , error ) {
800+ var configs []BuilderConfig
801+
802+ ng , err := txn .NodeGroupByName (name )
803+ if err != nil {
804+ if os .IsNotExist (errors .Cause (err )) {
805+ return configs , ErrBuildxNodeGroupNotFound
806+ }
807+
808+ return configs , fmt .Errorf ("can not query buildx node group '%s': %v" , name , err )
809+ }
810+
811+ if ng .Driver != "remote" {
812+ return configs , ErrIsNotRemoteDriver
813+ }
814+
815+ for _ , node := range ng .Nodes {
816+ for _ , plat := range node .Platforms {
817+ endpoint := BuilderConfig {
818+ Platform : plat .OS + "/" + plat .Architecture ,
819+ Arch : plat .Architecture ,
820+ FullBuildkitEndpoint : node .Endpoint ,
821+ }
822+
823+ if node .DriverOpts != nil {
824+ endpoint .ServerCAPath = node .DriverOpts ["cacert" ]
825+ endpoint .ClientCertPath = node .DriverOpts ["cert" ]
826+ endpoint .ClientKeyPath = node .DriverOpts ["key" ]
827+ }
828+
829+ configs = append (configs , endpoint )
830+ }
831+ }
832+
833+ return configs , nil
834+ }
835+
836+ func determineServerSideProxyStatus (ctx context.Context , dockerCli * command.DockerCli , name string ) ([]StatusData , error ) {
837+ descs := []StatusData {}
838+
839+ configs , err := readRemoteBuilderConfigs (dockerCli , name )
840+ if err != nil {
841+ if err == ErrBuildxNodeGroupNotFound || err == ErrIsNotRemoteDriver {
842+ return nil , nil
843+ }
844+
845+ return nil , err
846+ }
847+
848+ for _ , cfg := range configs {
849+ if ! isNamespaceBuildkitEndpoint (cfg .FullBuildkitEndpoint ) {
850+ continue
851+ }
852+
853+ status := StatusData {
854+ Platform : cfg .Platform ,
855+ IsServerSideProxy : true ,
856+ Status : ProxyStatus_ServerSide ,
857+ }
858+
859+ if _ , err := TestServerSideBuildxProxyConnectivity (ctx , cfg ); err != nil {
860+ status .Status = ProxyStatus_ServerSideUnreachable
861+ status .LastError = err .Error ()
862+ }
863+
864+ descs = append (descs , status )
865+ }
866+
798867 return descs , err
799868}
800869
0 commit comments