This is an automated email from the ASF dual-hosted git repository.

tsato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fce62bd0 fix(lint): fix more forcetypeassert
9fce62bd0 is described below

commit 9fce62bd049e944ea308de282d0d6a3bcaa32416
Author: Tadayoshi Sato <sato.tadayo...@gmail.com>
AuthorDate: Thu Jun 9 19:42:37 2022 +0900

    fix(lint): fix more forcetypeassert
---
 cmd/util/doc-gen/generators/traitdocgen.go | 16 ++++++++++++----
 pkg/util/kubernetes/collection.go          | 14 ++++++++++++--
 pkg/util/kubernetes/util.go                |  4 +++-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/cmd/util/doc-gen/generators/traitdocgen.go 
b/cmd/util/doc-gen/generators/traitdocgen.go
index 9c1f084be..7e701e108 100644
--- a/cmd/util/doc-gen/generators/traitdocgen.go
+++ b/cmd/util/doc-gen/generators/traitdocgen.go
@@ -84,8 +84,12 @@ func (g *traitDocGen) Filter(context *generator.Context, t 
*types.Type) bool {
 }
 
 func (g *traitDocGen) GenerateType(context *generator.Context, t *types.Type, 
out io.Writer) error {
-       docDir := g.arguments.CustomArgs.(*CustomArgs).DocDir
-       traitPath := g.arguments.CustomArgs.(*CustomArgs).TraitPath
+       customArgs, ok := g.arguments.CustomArgs.(*CustomArgs)
+       if !ok {
+               return fmt.Errorf("type assertion failed: %v", 
g.arguments.CustomArgs)
+       }
+       docDir := customArgs.DocDir
+       traitPath := customArgs.TraitPath
        traitID := getTraitID(t)
        traitFile := traitID + ".adoc"
        filename := path.Join(docDir, traitPath, traitFile)
@@ -108,8 +112,12 @@ func (g *traitDocGen) Finalize(c *generator.Context, w 
io.Writer) error {
 }
 
 func (g *traitDocGen) FinalizeNav(*generator.Context) error {
-       docDir := g.arguments.CustomArgs.(*CustomArgs).DocDir
-       navPath := g.arguments.CustomArgs.(*CustomArgs).NavPath
+       customArgs, ok := g.arguments.CustomArgs.(*CustomArgs)
+       if !ok {
+               return fmt.Errorf("type assertion failed: %v", 
g.arguments.CustomArgs)
+       }
+       docDir := customArgs.DocDir
+       navPath := customArgs.NavPath
        filename := path.Join(docDir, navPath)
 
        return util.WithFileContent(filename, func(file *os.File, data []byte) 
error {
diff --git a/pkg/util/kubernetes/collection.go 
b/pkg/util/kubernetes/collection.go
index 54e344905..0a0579f41 100644
--- a/pkg/util/kubernetes/collection.go
+++ b/pkg/util/kubernetes/collection.go
@@ -157,7 +157,12 @@ func (c *Collection) RemoveDeployment(filter 
func(*appsv1.Deployment) bool) *app
        if res == nil {
                return nil
        }
-       return res.(*appsv1.Deployment)
+       deploy, ok := res.(*appsv1.Deployment)
+       if !ok {
+               return nil
+       }
+
+       return deploy
 }
 
 // VisitConfigMap executes the visitor function on all ConfigMap resources.
@@ -191,7 +196,12 @@ func (c *Collection) RemoveConfigMap(filter 
func(*corev1.ConfigMap) bool) *corev
        if res == nil {
                return nil
        }
-       return res.(*corev1.ConfigMap)
+       cm, ok := res.(*corev1.ConfigMap)
+       if !ok {
+               return nil
+       }
+
+       return cm
 }
 
 // VisitService executes the visitor function on all Service resources.
diff --git a/pkg/util/kubernetes/util.go b/pkg/util/kubernetes/util.go
index f9fe01a51..3d029c202 100644
--- a/pkg/util/kubernetes/util.go
+++ b/pkg/util/kubernetes/util.go
@@ -51,7 +51,9 @@ func ToYAMLNoManagedFields(value runtime.Object) ([]byte, 
error) {
                return nil, err
        }
 
-       delete(mapdata["metadata"].(map[string]interface{}), "managedFields")
+       if m, ok := mapdata["metadata"].(map[string]interface{}); ok {
+               delete(m, "managedFields")
+       }
 
        return util.MapToYAML(mapdata)
 }

Reply via email to