Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectMeta attributes missing #2

Open
drewmullen opened this issue Apr 4, 2024 · 1 comment
Open

ObjectMeta attributes missing #2

drewmullen opened this issue Apr 4, 2024 · 1 comment

Comments

@drewmullen
Copy link
Owner

drewmullen commented Apr 4, 2024

When trying to use the client to query for a list of VMs, marshaling fails due to a series of fields missing from the object struct (example code at bottom):

$ go run main.go
panic: json: unknown field "annotations"

Generated object (missing fields): https://github.com/drewmullen/harvester-go-sdk/blob/main/model_k8s_io_v1_object_meta.go#L21-L26

swagger spec (missing fields): https://github.com/harvester/harvester/blob/master/api/openapi-spec/swagger.json#L10547-L10555

should have many other fields, such as annotations (complete field list): https://github.com/harvester/harvester/blob/master/vendor/k8s.io/apimachinery/pkg/apis/meta/v1/types.go#L111-L272

package main

import (
	"context"
	"fmt"
	"os"

	openapiclient "github.com/drewmullen/harvester-go-sdk"
)

func main() {

	api_token, server_url, namespace := os.Getenv("HARVESTER_API_TOKEN"), os.Getenv("HARVESTER_SERVER_URL"), os.Getenv("HARVESTER_NAMESPACE")

	if namespace == "" {
		namespace = "default"
	}
	if server_url == "" {
		fmt.Print("HARVESTER_SERVER_URL is not set")
		os.Exit(1)
	}
	if api_token == "" {
		fmt.Print("HARVESTER_API_TOKEN is not set")
		os.Exit(1)
	}

	configuration := &openapiclient.Configuration{
		DefaultHeader: make(map[string]string),
		UserAgent:     "OpenAPI-Generator/1.0.0/go",
		Debug:         false,
		Servers: openapiclient.ServerConfigurations{
			{
				URL:         server_url,
				Description: "Harvester API Server",
			},
		},
	}

	auth := context.WithValue(context.Background(), openapiclient.ContextAccessToken, api_token)
	apiClient := openapiclient.NewAPIClient(configuration)
	resp, r, err := apiClient.VirtualMachinesAPI.ListNamespacedVirtualMachine(auth, namespace).Execute()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `VirtualMachinesAPI.ListNamespacedVirtualMachine``: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
	// response from `ListNamespacedVirtualMachine`: KubevirtIoApiCoreV1VirtualMachineList
	fmt.Fprintf(os.Stdout, "Response from `VirtualMachinesAPI.ListNamespacedVirtualMachine`: %v\n", resp)
}
@drewmullen
Copy link
Owner Author

fixed by: harvester/harvester#5512

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant