diff --git a/controllers/cf/cf_pod_template_spec.go b/controllers/cf/cf_pod_template_spec.go index a5dbdaa1..089afb9d 100644 --- a/controllers/cf/cf_pod_template_spec.go +++ b/controllers/cf/cf_pod_template_spec.go @@ -219,11 +219,11 @@ func SanitizeBasePodSpec(log *zap.SugaredLogger, base *ar.ApicurioRegistryPodTem } currentContainer := common.GetContainerByName(current.Spec.Containers, f.REGISTRY_CONTAINER_NAME) if currentContainer == nil { - panic("could not find current registry container") + panic("Could not find the registry container in the current Deployment.") } factoryContainer := common.GetContainerByName(factory.Spec.Containers, f.REGISTRY_CONTAINER_NAME) if factoryContainer == nil { - panic("could not find factory registry container") + panic("Could not find the registry container in the initial Deployment.") } if len(base.Spec.Containers) > 0 && baseContainer != nil { diff --git a/controllers/client/client_crd.go b/controllers/client/client_crd.go index e3968dbf..24292e2d 100644 --- a/controllers/client/client_crd.go +++ b/controllers/client/client_crd.go @@ -37,7 +37,8 @@ func NewCRDClient(log *zap.Logger, scheme *runtime.Scheme, config *rest.Config) c, err := rest.UnversionedRESTClientFor(config2) if err != nil { - panic("Could not create CRD client.") + log.Sugar().Error(err) + panic("Could not create Kubernetes client for ApicurioRegistry CRD.") } return &CRDClient{ client: c, @@ -97,14 +98,16 @@ func (this *CRDClient) PatchApicurioRegistryStatus(namespace common.Namespace, n // Add "status" prefix to the patch path var original map[string]interface{} if err := json.Unmarshal(patchData, &original); err != nil { - panic(err) // TODO + this.log.Sugar().Error(err) + panic("Could not patch ApicurioRegistry status.") } extended := map[string]interface{}{ "status": original, } extendedPatchData, err := json.Marshal(extended) if err != nil { - panic(err) // TODO + this.log.Sugar().Error(err) + panic("Could not patch ApicurioRegistry status.") } result := &ar.ApicurioRegistry{} diff --git a/controllers/loop/context/context_impl.go b/controllers/loop/context/context_impl.go index 89c3afa3..c78d5009 100644 --- a/controllers/loop/context/context_impl.go +++ b/controllers/loop/context/context_impl.go @@ -81,7 +81,7 @@ func (this *loopContext) Finalize() (bool, time.Duration) { this.requeueDelay = 0 }() if this.reconcileSequence == math.MaxInt64 { - panic("int64 counter overflow. Restarting to reset.") // This will probably never happen + panic("int64 counter overflow. Restarting to reset.") // This will never happen } this.reconcileSequence += 1 return this.requeue, this.requeueDelay diff --git a/controllers/loop/context/context_mock.go b/controllers/loop/context/context_mock.go index bef043a8..9ed09842 100644 --- a/controllers/loop/context/context_mock.go +++ b/controllers/loop/context/context_mock.go @@ -47,20 +47,20 @@ func (this *LoopContextMock) GetAppNamespace() c.Namespace { } func (this *LoopContextMock) SetRequeueNow() { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) SetRequeueDelaySoon() { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) SetRequeueDelaySec(delay uint) { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) Finalize() (bool, time.Duration) { if this.reconcileSequence == math.MaxInt64 { - panic("int64 counter overflow. Restarting to reset.") // This will probably never happen + panic("int64 counter overflow. Restarting to reset.") // This will never happen } this.reconcileSequence += 1 return false, 0 @@ -71,7 +71,7 @@ func (this *LoopContextMock) GetResourceCache() resources.ResourceCache { } func (this *LoopContextMock) GetClients() *client.Clients { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) GetEnvCache() env.EnvCache { @@ -87,11 +87,11 @@ func (this *LoopContextMock) GetAttempts() int { } func (this *LoopContextMock) GetTestingSupport() *c.TestSupport { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) GetSupportedFeatures() *c.SupportedFeatures { - panic("Not implemented") + panic("not implemented") } func (this *LoopContextMock) GetReconcileSequence() int64 { diff --git a/controllers/loop/impl/control_loop_impl.go b/controllers/loop/impl/control_loop_impl.go index 6907ee1d..6981ca86 100644 --- a/controllers/loop/impl/control_loop_impl.go +++ b/controllers/loop/impl/control_loop_impl.go @@ -64,7 +64,10 @@ func (this *controlLoopImpl) Run() { } } if attempt == maxAttempts { - panic("control loop stabilization limit exceeded") + panic("Control loop stabilization limit exceeded. Explanation: The operator is separated into multiple functions, " + + "that are each responsible for a single task, such as applying env. variables to a Deployment. " + + "They are each executed until the desired state of the cached resource (e.g. the Deployment) is reached, and can be updated on the cluster. " + + "This error occurs when the functions could not reach the desired state within a limited number of attempts.") } this.services.AfterRun() diff --git a/controllers/loop/services/services_mock.go b/controllers/loop/services/services_mock.go index 9248d71d..92bc71f3 100644 --- a/controllers/loop/services/services_mock.go +++ b/controllers/loop/services/services_mock.go @@ -29,21 +29,21 @@ func (this *LoopServicesMock) AfterRun() { } func (this *LoopServicesMock) GetPatchers() *patcher.Patchers { - panic("Not implemented") + panic("not implemented") } func (this *LoopServicesMock) GetKubeFactory() *factory.KubeFactory { - panic("Not implemented") + panic("not implemented") } func (this *LoopServicesMock) GetMonitoringFactory() *factory.MonitoringFactory { - panic("Not implemented") + panic("not implemented") } func (this *LoopServicesMock) GetConditionManager() conditions.ConditionManager { - panic("Not implemented") + panic("not implemented") } func (this *LoopServicesMock) GetStatus() *status.Status { - panic("Not implemented") + panic("not implemented") } diff --git a/controllers/svc/env/env_cache_impl.go b/controllers/svc/env/env_cache_impl.go index 5ad9da06..1ca35be6 100644 --- a/controllers/svc/env/env_cache_impl.go +++ b/controllers/svc/env/env_cache_impl.go @@ -84,7 +84,7 @@ func (this *envCacheEntryBuilder) SetPriority(priority Priority) EnvCacheEntryBu func (this *envCacheEntryBuilder) Build() EnvCacheEntry { if strings.TrimSpace(this.entry.GetName()) == "" { - panic("Environment variable can not be empty nor whitespace") + panic("Environment variable name cannot be empty nor contain only whitespace.") } return this.entry } @@ -202,7 +202,10 @@ func (this *envCache) computeSorted() { func (this *envCache) processWithDependencies(depth int, processed map[string]bool, val EnvCacheEntry) { if depth > len(this.cache) { - panic("Cycle detected during the processing of environment variables.") + panic("Cycle detected during the processing of environment variables (at " + val.GetName() + "), make sure that every env. variable is define once. " + + "Explanation: Ordering of the env. variables is significant, because some variables can reference others using interpolation. " + + "As a result, the operator tries to keep the order consistent (e.g. as defined in the CR). " + + "This error occurs when the operator could not order the variables correctly.") } if _, exists := processed[val.GetName()]; !exists && !this.WasDeleted(val.GetName()) { // Was not yet processed for _, dependencyName := range val.GetDependencies() { // Process & add deps first diff --git a/controllers/svc/factory/factory_kube.go b/controllers/svc/factory/factory_kube.go index 0909b4b8..652d6ebe 100644 --- a/controllers/svc/factory/factory_kube.go +++ b/controllers/svc/factory/factory_kube.go @@ -38,11 +38,11 @@ func (this *KubeFactory) GetLabels() map[string]string { registryVersion := os.Getenv(ENV_REGISTRY_VERSION) if registryVersion == "" { - panic("Could not determine registry version. Environment variable '" + ENV_REGISTRY_VERSION + "' is empty.") + panic("Could not determine Registry version. Environment variable '" + ENV_REGISTRY_VERSION + "' is empty.") } operatorName := os.Getenv(ENV_OPERATOR_NAME) if operatorName == "" { - panic("Could not determine operator name. Environment variable '" + ENV_OPERATOR_NAME + "' is empty.") + panic("Could not determine Operator name. Environment variable '" + ENV_OPERATOR_NAME + "' is empty.") } app := this.ctx.GetAppName().Str() @@ -180,7 +180,7 @@ func (this *KubeFactory) CreateService() *core.Service { func (this *KubeFactory) CreateIngress(serviceName string) *networking.Ingress { if serviceName == "" { - panic("Required argument.") + panic("Required argument, Ingress name, is empty.") } metaData := this.createObjectMeta("ingress") metaData.Annotations = map[string]string{ diff --git a/controllers/svc/patcher/patcher_kube.go b/controllers/svc/patcher/patcher_kube.go index da17c4b2..ac63473b 100644 --- a/controllers/svc/patcher/patcher_kube.go +++ b/controllers/svc/patcher/patcher_kube.go @@ -57,7 +57,7 @@ func (this *KubePatcher) patchApicurioRegistry() { // TODO move to separate file "ar.ApicurioRegistry", func(owner meta.Object, namespace c.Namespace, value interface{}) (interface{}, error) { // This should be not used (at the moment) - panic("Unsupported operation.") + panic("unsupported operation") }, func(namespace c.Namespace, name c.Name, data []byte) (interface{}, error) { return this.ctx.GetClients().CRD().PatchApicurioRegistry(namespace, name, data) @@ -97,7 +97,7 @@ func (this *KubePatcher) patchApicurioRegistryStatus() { "ar.ApicurioRegistryStatus", func(owner meta.Object, namespace c.Namespace, value interface{}) (interface{}, error) { // This should be not used (at the moment) - panic("Unsupported operation.") + panic("unsupported operation") }, func(namespace c.Namespace, name c.Name, data []byte) (interface{}, error) { return this.ctx.GetClients().CRD().PatchApicurioRegistryStatus(namespace, name, data) diff --git a/controllers/svc/patcher/patchers.go b/controllers/svc/patcher/patchers.go index dd97242a..dd48d129 100644 --- a/controllers/svc/patcher/patchers.go +++ b/controllers/svc/patcher/patchers.go @@ -102,7 +102,8 @@ func patchGeneric( // Optimization: Check if the patch is empty var patchJson map[string]interface{} if err := json.Unmarshal(patchData, &patchJson); err != nil { - panic(err) // TODO + ctx.GetLog().Sugar().Error(err) + panic("Could not patch a resource: " + typeString) } if patchJson == nil || len(patchJson) == 0 { //ctx.GetLog().WithValues("resource", typeString, "name", name, "patch", string(patchData)). diff --git a/controllers/svc/status/conditions/conditions_impl.go b/controllers/svc/status/conditions/conditions_impl.go index 08769e94..26c7af49 100644 --- a/controllers/svc/status/conditions/conditions_impl.go +++ b/controllers/svc/status/conditions/conditions_impl.go @@ -29,7 +29,7 @@ func (this *condition) GetData() *metav1.Condition { func (this *condition) Reset() { if this.ctype == "" { - panic("Condition type not set!") + panic("Condition type is empty.") } if this.data == nil { this.data = &metav1.Condition{ diff --git a/controllers/svc/status/status.go b/controllers/svc/status/status.go index ae1d6c6d..115ba351 100644 --- a/controllers/svc/status/status.go +++ b/controllers/svc/status/status.go @@ -58,7 +58,7 @@ func (this *Status) init() { func (this *Status) set(mapp map[string]string, key string, value string) { ptr := &value if key == "" { - panic("Fatal: Empty key for " + *ptr) + panic("Status key is empty for value: " + *ptr) } mapp[key] = *ptr } @@ -81,7 +81,7 @@ func (this *Status) SetConfigInt32P(key string, value *int32) { func (this *Status) GetConfig(key string) string { v, ok := this.config[key] if !ok { - panic("Fatal: Status key '" + key + "' not found.") + panic("Value that belongs to status key " + key + " not found.") } return v }