Skip to content

tinygo with work kubernetes crds? #3319

@zirain

Description

@zirain

I want to use TinyGo with following code:

package main

import (
	"fmt"

	workloadv1alpha1 "github.com/karmada-io/karmada/examples/customresourceinterpreter/apis/workload/v1alpha1"
	configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
	"github.com/karmada-io/karmada/pkg/resourceinterpreter/customizedinterpreter/webhook"
	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
	"k8s.io/apimachinery/pkg/runtime"
)

func main() {

}

func Interpreter(req *webhook.RequestAttributes) *webhook.ResponseAttributes {
	switch req.Operation {
	case configv1alpha1.InterpreterOperationInterpretReplica:
		return responseWithExploreReplica(req)
	default:
		return nil
	}
}

func responseWithExploreReplica(req *webhook.RequestAttributes) *webhook.ResponseAttributes {
	wantedWorkload := &workloadv1alpha1.Workload{}
	if err := convertToTypedObject(req.Object, wantedWorkload); err != nil {
		return nil
	}
	return &webhook.ResponseAttributes{
		Replicas: *wantedWorkload.Spec.Replicas + 1,
	}
}

// convertToTypedObject converts an unstructured object to typed.
func convertToTypedObject(in, out interface{}) error {
	if in == nil || out == nil {
		return fmt.Errorf("convert objects should not be nil")
	}

	switch v := in.(type) {
	case *unstructured.Unstructured:
		return runtime.DefaultUnstructuredConverter.FromUnstructured(v.UnstructuredContent(), out)
	case map[string]interface{}:
		return runtime.DefaultUnstructuredConverter.FromUnstructured(v, out)
	default:
		return fmt.Errorf("convert object must be pointer of unstructured or map[string]interface{}")
	}
}

but got error like following:

# [k8s.io/apimachinery/third_party/forked/golang/reflect](http://k8s.io/apimachinery/third_party/forked/golang/reflect)
../../../../../../pkg/mod/k8s.io/apimachinery@v0.25.4/third_party/forked/golang/reflect/deep_equal.go:126:15: v1.UnsafeAddr undefined (type "reflect".Value has no field or method UnsafeAddr)
../../../../../../pkg/mod/k8s.io/apimachinery@v0.25.4/third_party/forked/golang/reflect/deep_equal.go:127:15: v2.UnsafeAddr undefined (type "reflect".Value has no field or method UnsafeAddr)
../../../../../../pkg/mod/k8s.io/apimachinery@v0.25.4/third_party/forked/golang/reflect/deep_equal.go:314:15: v1.UnsafeAddr undefined (type "reflect".Value has no field or method UnsafeAddr)
../../../../../../pkg/mod/k8s.io/apimachinery@v0.25.4/third_party/forked/golang/reflect/deep_equal.go:315:15: v2.UnsafeAddr undefined (type "reflect".Value has no field or method UnsafeAddr)
make: *** [Makefile:7: build-wasm] Error 1

How can I make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions