Skip to content
Snippets Groups Projects
Commit d2daa4e2 authored by Song.Jin's avatar Song.Jin
Browse files

allow it to disable CRD creation

parent 65b0c919
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,7 @@ type Config struct { ...@@ -40,6 +40,7 @@ type Config struct {
InCluster bool `json:"inCluster"` InCluster bool `json:"inCluster"`
KubeConfigFile string `json:"kubeConfigFile"` KubeConfigFile string `json:"kubeConfigFile"`
UseTPR bool `json:"useTPR"` // Flag option to use TPRs instead of CRDs UseTPR bool `json:"useTPR"` // Flag option to use TPRs instead of CRDs
NoCrdCreation bool `json:"noCrdCreation"` // Flag to disable creation of CRDs at cluster level
} }
// Open returns a storage using Kubernetes third party resource. // Open returns a storage using Kubernetes third party resource.
...@@ -85,37 +86,38 @@ func (c *Config) open(logger logrus.FieldLogger, waitForResources bool) (*client ...@@ -85,37 +86,38 @@ func (c *Config) open(logger logrus.FieldLogger, waitForResources bool) (*client
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
if !c.NoCrdCreation {
logger.Info("creating custom Kubernetes resources")
if !cli.registerCustomResources(c.UseTPR) {
if waitForResources {
cancel()
return nil, fmt.Errorf("failed creating custom resources")
}
logger.Info("creating custom Kubernetes resources") // Try to synchronously create the custom resources once. This doesn't mean
if !cli.registerCustomResources(c.UseTPR) { // they'll immediately be available, but ensures that the client will actually try
if waitForResources { // once.
cancel() logger.Errorf("failed creating custom resources: %v", err)
return nil, fmt.Errorf("failed creating custom resources") go func() {
} for {
if cli.registerCustomResources(c.UseTPR) {
// Try to synchronously create the custom resources once. This doesn't mean return
// they'll immediately be available, but ensures that the client will actually try }
// once.
logger.Errorf("failed creating custom resources: %v", err) select {
go func() { case <-ctx.Done():
for { return
if cli.registerCustomResources(c.UseTPR) { case <-time.After(30 * time.Second):
return }
} }
}()
}
select { if waitForResources {
case <-ctx.Done(): if err := cli.waitForCRDs(ctx); err != nil {
return cancel()
case <-time.After(30 * time.Second): return nil, err
}
} }
}()
}
if waitForResources {
if err := cli.waitForCRDs(ctx); err != nil {
cancel()
return nil, err
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment