11package kubernetes
22
33import (
4- "context"
54 "errors"
65 "fmt"
76 "github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/collections"
87 "github.com/bf2fc6cc711aee1a0c2a/cos-tools/rhoc/pkg/util/kubernetes/pods"
8+ "github.com/redhat-developer/app-services-cli/pkg/shared/factory"
99 "io"
1010 kerr "k8s.io/apimachinery/pkg/api/errors"
1111 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -18,19 +18,19 @@ import (
1818)
1919
2020type Client struct {
21- ctx context. Context
21+ f * factory. Factory
2222 config * r.Config
2323 C k.Interface
2424}
2525
26- func NewClient (ctx context. Context , config * r.Config ) (* Client , error ) {
26+ func NewClient (f * factory. Factory , config * r.Config ) (* Client , error ) {
2727 client , err := k .NewForConfig (config )
2828 if err != nil {
2929 return nil , err
3030 }
3131
3232 answer := Client {
33- ctx : ctx ,
33+ f : f ,
3434 config : config ,
3535 C : client ,
3636 }
@@ -89,13 +89,15 @@ func (in *Client) List(resources []schema.GroupVersionResource, options metav1.L
8989 continue
9090 }
9191
92- resList , err := dc .Resource (gvr ).List (in .ctx , options )
92+ resList , err := dc .Resource (gvr ).List (in .f . Context , options )
9393
9494 if err != nil {
9595 switch {
9696 case kerr .IsUnauthorized (err ):
97+ in .f .Logger .Errorf ("Unauthorized access to %s:%s" , gvr .GroupVersion (), gvr .Resource )
9798 continue
9899 case kerr .IsForbidden (err ):
100+ in .f .Logger .Errorf ("Forbidden access to %s:%s" , gvr .GroupVersion (), gvr .Resource )
99101 continue
100102 default :
101103 return nil , err
@@ -114,7 +116,7 @@ func (in *Client) List(resources []schema.GroupVersionResource, options metav1.L
114116}
115117
116118func (in * Client ) Logs (namespace string , name string , writer io.Writer ) error {
117- containers , err := pods .ListContainers (in .ctx , in .C , namespace , name )
119+ containers , err := pods .ListContainers (in .f . Context , in .C , namespace , name )
118120 if err != nil {
119121 return err
120122 }
@@ -141,7 +143,7 @@ func (in *Client) LogsForContainer(namespace string, name string, container stri
141143 return err
142144 }
143145
144- err = pods .Logs (in .ctx , in .C , namespace , name , container , writer )
146+ err = pods .Logs (in .f . Context , in .C , namespace , name , container , writer )
145147 if err != nil && ! errors .Is (err , io .EOF ) {
146148 return err
147149 }
0 commit comments