-
Notifications
You must be signed in to change notification settings - Fork 293
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi, I'm trying to use the Go client to create ComputeInstance resources but schema validation fails.
I'm not sure what I'm doing wrong, this is a small client I use to reproduce the error:
package main
import (
"context"
"fmt"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/k8s/v1alpha1"
"log"
gcloud "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/apis/compute/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var kclient client.Client
func init() {
kclient = GetClient()
}
func GetClient() client.Client {
scheme := runtime.NewScheme()
gcloud.AddToScheme(scheme)
kubeconfig := ctrl.GetConfigOrDie()
controllerClient, err := client.New(kubeconfig, client.Options{Scheme: scheme})
if err != nil {
log.Fatal(err)
return nil
}
return controllerClient
}
func CreateComputeInstance(instance *gcloud.ComputeInstance) (err error) {
err = kclient.Create(context.TODO(), instance)
return err
}
func main() {
testInstance := &gcloud.ComputeInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "test-instance",
Namespace: "config-connector",
Labels: make(map[string]string),
Annotations: make(map[string]string),
},
Spec: gcloud.ComputeInstanceSpec{
BootDisk: gcloud.BootDisk{
AutoDelete: true,
InitializeParams: gcloud.InitializeParams{
Size: 20,
SourceImageRef: v1alpha1.ResourceRef{
External: "debian-cloud/debian-9",
},
Type: "pd-ssd",
},
},
MachineType: "n1-standard-1",
NetworkInterface: []gcloud.NetworkInterface{
{
NetworkRef: v1alpha1.ResourceRef{
Name: "default",
},
SubnetworkRef: v1alpha1.ResourceRef{
Name: "default",
},
},
},
Zone: "europe-west1-b",
},
}
err:= CreateComputeInstance(testInstance)
fmt.Printf("Error %v", err)
}
result:
Error ComputeInstance.compute.cnrm.cloud.google.com "test-instance" is invalid: [: Invalid value: "": "spec.instanceTemplateRef" must validate one and only one schema (oneOf). Found none valid, spec.instanceTemplateRef.name: Required value, spec.confidentialInstanceConfig.enableConfidentialCompute: Required value, : Invalid value: "": "spec.serviceAccount.serviceAccountRef" must validate one and only one schema (oneOf). Found none valid, spec.serviceAccount.serviceAccountRef.name: Required value, spec.serviceAccount.scopes: Required value, : Invalid value: "": "spec.bootDisk.sourceDiskRef" must validate one and only one schema (oneOf). Found none valid, spec.bootDisk.sourceDiskRef.name: Required value, spec.bootDisk.diskEncryptionKeyRaw.valueFrom.secretKeyRef.name: Required value, spec.bootDisk.diskEncryptionKeyRaw.valueFrom.secretKeyRef.key: Required value, : Invalid value: "": "spec.bootDisk.kmsKeyRef" must validate one and only one schema (oneOf). Found none valid, spec.bootDisk.kmsKeyRef.name: Required value]
instead if I try to create the instance using kubectl and a yaml manifest i get no errors:
kubectl apply -f testinstance.yaml
computeinstance.compute.cnrm.cloud.google.com/test-instance created
testinstance.yaml file contents:
apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeInstance
metadata:
name: test-instance
spec:
machineType: n1-standard-1
zone: europe-west1-b
bootDisk:
initializeParams:
size: 24
type: pd-ssd
sourceImageRef:
external: debian-cloud/debian-9
networkInterface:
- subnetworkRef:
name: default
It seems like validation fails to interpret default values as empty/zero
PS. Go Client version: v1.41.0, config-connector-operator image: gcr.io/gke-release/cnrm/operator:f3b1091
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working