@@ -18,102 +18,102 @@ import (
1818 "github.com/joelanford/kubectl-operator/internal/pkg/log"
1919)
2020
21- type InstallCatalog struct {
21+ type AddCatalog struct {
2222 config * Configuration
2323
2424 IndexImage string
2525 DisplayName string
2626 Publisher string
27- InstallTimeout time.Duration
27+ AddTimeout time.Duration
2828 CleanupTimeout time.Duration
2929
3030 RegistryOptions []containerdregistry.RegistryOption
3131
3232 registry * containerdregistry.Registry
3333}
3434
35- func NewInstallCatalog (cfg * Configuration ) * InstallCatalog {
36- return & InstallCatalog {
35+ func NewAddCatalog (cfg * Configuration ) * AddCatalog {
36+ return & AddCatalog {
3737 config : cfg ,
3838 }
3939}
4040
41- func (i * InstallCatalog ) BindFlags (fs * pflag.FlagSet ) {
42- fs .StringVarP (& i .DisplayName , "display-name" , "d" , "" , "display name of the index" )
43- fs .StringVarP (& i .Publisher , "publisher" , "p" , "" , "publisher of the index" )
44- fs .DurationVarP (& i . InstallTimeout , "timeout" , "t" , time .Minute , "the amount of time to wait before cancelling the install " )
45- fs .DurationVar (& i .CleanupTimeout , "cleanup-timeout" , time .Minute , "the amount to time to wait before cancelling cleanup" )
41+ func (a * AddCatalog ) BindFlags (fs * pflag.FlagSet ) {
42+ fs .StringVarP (& a .DisplayName , "display-name" , "d" , "" , "display name of the index" )
43+ fs .StringVarP (& a .Publisher , "publisher" , "p" , "" , "publisher of the index" )
44+ fs .DurationVarP (& a . AddTimeout , "timeout" , "t" , time .Minute , "the amount of time to wait before cancelling the catalog addition " )
45+ fs .DurationVar (& a .CleanupTimeout , "cleanup-timeout" , time .Minute , "the amount to time to wait before cancelling cleanup" )
4646}
4747
48- func (i * InstallCatalog ) Run (ctx context.Context ) (* v1alpha1.CatalogSource , error ) {
48+ func (a * AddCatalog ) Run (ctx context.Context ) (* v1alpha1.CatalogSource , error ) {
4949 var err error
50- i .registry , err = containerdregistry .NewRegistry (i .RegistryOptions ... )
50+ a .registry , err = containerdregistry .NewRegistry (a .RegistryOptions ... )
5151 if err != nil {
5252 return nil , err
5353 }
5454
5555 defer func () {
56- if err := i .registry .Destroy (); err != nil {
56+ if err := a .registry .Destroy (); err != nil {
5757 log .Printf ("registry cleanup: %v" , err )
5858 }
5959 }()
6060
61- imageRef , err := container .ImageFromString (i .IndexImage )
61+ imageRef , err := container .ImageFromString (a .IndexImage )
6262 if err != nil {
6363 return nil , err
6464 }
6565 csKey := types.NamespacedName {
66- Namespace : i .config .Namespace ,
66+ Namespace : a .config .Namespace ,
6767 Name : imageRef .Name ,
6868 }
6969
70- labels , err := i .labelsFor (ctx , i .IndexImage )
70+ labels , err := a .labelsFor (ctx , a .IndexImage )
7171 if err != nil {
7272 return nil , err
7373 }
7474
75- i .setDefaults (labels )
75+ a .setDefaults (labels )
7676
7777 opts := []catalog.Option {
78- catalog .Image (i .IndexImage ),
79- catalog .DisplayName (i .DisplayName ),
80- catalog .Publisher (i .Publisher ),
78+ catalog .Image (a .IndexImage ),
79+ catalog .DisplayName (a .DisplayName ),
80+ catalog .Publisher (a .Publisher ),
8181 }
8282 cs := catalog .Build (csKey , opts ... )
83- if err := i . install (ctx , cs ); err != nil {
84- defer i .cleanup (cs )
83+ if err := a . add (ctx , cs ); err != nil {
84+ defer a .cleanup (cs )
8585 return nil , err
8686 }
8787 return cs , nil
8888}
8989
90- func (i * InstallCatalog ) labelsFor (ctx context.Context , indexImage string ) (map [string ]string , error ) {
90+ func (a * AddCatalog ) labelsFor (ctx context.Context , indexImage string ) (map [string ]string , error ) {
9191 simpleRef := image .SimpleReference (indexImage )
92- if err := i .registry .Pull (ctx , simpleRef ); err != nil {
92+ if err := a .registry .Pull (ctx , simpleRef ); err != nil {
9393 return nil , fmt .Errorf ("pull image: %v" , err )
9494 }
95- labels , err := i .registry .Labels (ctx , simpleRef )
95+ labels , err := a .registry .Labels (ctx , simpleRef )
9696 if err != nil {
9797 return nil , fmt .Errorf ("get image labels: %v" , err )
9898 }
9999 return labels , nil
100100}
101101
102- func (i * InstallCatalog ) setDefaults (labels map [string ]string ) {
103- if i .DisplayName == "" {
102+ func (a * AddCatalog ) setDefaults (labels map [string ]string ) {
103+ if a .DisplayName == "" {
104104 if v , ok := labels ["operators.operatorframework.io.index.display-name" ]; ok {
105- i .DisplayName = v
105+ a .DisplayName = v
106106 }
107107 }
108- if i .Publisher == "" {
108+ if a .Publisher == "" {
109109 if v , ok := labels ["operators.operatorframework.io.index.publisher" ]; ok {
110- i .Publisher = v
110+ a .Publisher = v
111111 }
112112 }
113113}
114114
115- func (i * InstallCatalog ) install (ctx context.Context , cs * v1alpha1.CatalogSource ) error {
116- if err := i .config .Client .Create (ctx , cs ); err != nil {
115+ func (a * AddCatalog ) add (ctx context.Context , cs * v1alpha1.CatalogSource ) error {
116+ if err := a .config .Client .Create (ctx , cs ); err != nil {
117117 return fmt .Errorf ("create catalogsource: %v" , err )
118118 }
119119
@@ -122,7 +122,7 @@ func (i *InstallCatalog) install(ctx context.Context, cs *v1alpha1.CatalogSource
122122 return fmt .Errorf ("get catalogsource key: %v" , err )
123123 }
124124 if err := wait .PollImmediateUntil (time .Millisecond * 250 , func () (bool , error ) {
125- if err := i .config .Client .Get (ctx , csKey , cs ); err != nil {
125+ if err := a .config .Client .Get (ctx , csKey , cs ); err != nil {
126126 return false , err
127127 }
128128 if cs .Status .GRPCConnectionState != nil {
@@ -137,10 +137,10 @@ func (i *InstallCatalog) install(ctx context.Context, cs *v1alpha1.CatalogSource
137137 return nil
138138}
139139
140- func (i * InstallCatalog ) cleanup (cs * v1alpha1.CatalogSource ) {
141- ctx , cancel := context .WithTimeout (context .Background (), i .CleanupTimeout )
140+ func (a * AddCatalog ) cleanup (cs * v1alpha1.CatalogSource ) {
141+ ctx , cancel := context .WithTimeout (context .Background (), a .CleanupTimeout )
142142 defer cancel ()
143- if err := i .config .Client .Delete (ctx , cs ); err != nil {
143+ if err := a .config .Client .Delete (ctx , cs ); err != nil {
144144 log .Printf ("delete catalogsource %q: %v" , cs .Name , err )
145145 }
146146}
0 commit comments