From 1ad33d48669e229c48a9cf3411ed237ed678cb1c Mon Sep 17 00:00:00 2001 From: akutz Date: Mon, 12 Dec 2022 11:32:17 -0600 Subject: [PATCH] fix: Heal the broken Namespace API This patch fixes a few bugs related to the Namespaces API. There was an NPE occurring due to a pointer variable being used prior to being assigned. The "govc namespace.logs.download" command also just failed to work due to the VAPI client assuming the response will always be JSON and not possibly, binary data as one sends when one receives a tar file. Finally, the namespace.bats file used to use the cluster name "Workload-Cluster", but due to a hack in the simulated namespaces API, it only recognizes clusters that begin with "WCP". --- govc/namespace/cluster/enable.go | 1 + govc/namespace/cluster/logs.go | 4 ++++ govc/test/namespace.bats | 8 ++++---- vapi/namespace/namespace.go | 14 +++++++++----- vapi/namespace/simulator/simulator.go | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/govc/namespace/cluster/enable.go b/govc/namespace/cluster/enable.go index 0a5515932..8170a7782 100644 --- a/govc/namespace/cluster/enable.go +++ b/govc/namespace/cluster/enable.go @@ -310,6 +310,7 @@ func (cmd *enableCluster) toVapiSpec(refs objectReferences) (*namespace.EnableCl if (cmd.ControlPlaneManagementNetwork.Mode != "") || (cmd.ControlPlaneManagementNetwork.FloatingIP != "") || (cmd.ControlPlaneManagementNetwork.Network != "") { + masterManagementNetwork = &namespace.MasterManagementNetwork{} masterManagementNetwork.AddressRange = cmd.ControlPlaneManagementNetwork.AddressRange masterManagementNetwork.FloatingIP = cmd.ControlPlaneManagementNetwork.FloatingIP ipam := namespace.IpAssignmentModeFromString(cmd.ControlPlaneManagementNetwork.Mode) diff --git a/govc/namespace/cluster/logs.go b/govc/namespace/cluster/logs.go index 9bc1748bf..80808f734 100644 --- a/govc/namespace/cluster/logs.go +++ b/govc/namespace/cluster/logs.go @@ -86,6 +86,10 @@ func (cmd *logs) Run(ctx context.Context, f *flag.FlagSet) error { return err } + if id := c.SessionID(); id != "" { + req.Header.Set("vmware-api-session-id", id) + } + return c.Client.Do(ctx, req, func(res *http.Response) error { if name == "" { d := res.Header.Get("Content-Disposition") diff --git a/govc/test/namespace.bats b/govc/test/namespace.bats index a21874568..a0bd7b170 100755 --- a/govc/test/namespace.bats +++ b/govc/test/namespace.bats @@ -32,7 +32,7 @@ load test_helper vcsim_env # need to set up some dependencies - govc cluster.create Workload-Cluster + govc cluster.create WCP-Cluster assert_success govc dvs.create "DVPG-Management Network" @@ -41,7 +41,7 @@ load test_helper govc namespace.cluster.enable \ --service-cidr 10.96.0.0/23 \ --pod-cidrs 10.244.0.0/20 \ - --cluster "Workload-Cluster" \ + --cluster "WCP-Cluster" \ --control-plane-dns 8.8.8.8 \ --worker-dns 8.8.8.8 \ --control-plane-dns-search-domains example.com \ @@ -67,10 +67,10 @@ load test_helper @test "namespace.cluster.disable" { vcsim_env - govc cluster.create Workload-Cluster + govc cluster.create WCP-Cluster assert_success - govc namespace.cluster.disable --cluster Workload-Cluster + govc namespace.cluster.disable --cluster WCP-Cluster assert_success } diff --git a/vapi/namespace/namespace.go b/vapi/namespace/namespace.go index 99245310a..7a1c8d30d 100644 --- a/vapi/namespace/namespace.go +++ b/vapi/namespace/namespace.go @@ -338,7 +338,9 @@ type AviConfigCreateSpec struct { // a Tanzu Kubernetes Grid enabled vSphere cluster to a HA Proxy // Load Balancer. // Note: HA Proxy is not supported in vSphere 7.0u3 and above. Use Avi -// with vSphere networking, or NSX-T networking, instead. +// +// with vSphere networking, or NSX-T networking, instead. +// // See https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/data-structures/NamespaceManagement/LoadBalancers/HAProxyConfigCreateSpec/ // Since 7.0u1:- type HAProxyConfigCreateSpec struct { @@ -352,10 +354,12 @@ type HAProxyConfigCreateSpec struct { // the Load Balancer technology in use in a Tanzu Kubernetes Grid // cluster. // Note: If invalid or undefined (E.g. if a newer/older vSphere -// version is used whose option isn't listed) then the -// UndefinedLoadBalancerProvider value shall be set. -// This translates to an empty string, removing its element -// from the produces JSON. +// +// version is used whose option isn't listed) then the +// UndefinedLoadBalancerProvider value shall be set. +// This translates to an empty string, removing its element +// from the produces JSON. +// // See https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/data-structures/NamespaceManagement/LoadBalancers/Provider/ type LoadBalancerProvider struct { slug string diff --git a/vapi/namespace/simulator/simulator.go b/vapi/namespace/simulator/simulator.go index afde46bdf..55382fb80 100644 --- a/vapi/namespace/simulator/simulator.go +++ b/vapi/namespace/simulator/simulator.go @@ -137,7 +137,7 @@ func (h *Handler) clustersSupportBundle(w http.ResponseWriter, r *http.Request) name := fmt.Sprintf("wcp-support-bundle-%s-%s--00-00.tar", id, time.Now().Format("2006Jan02")) w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", name)) - r.Header.Set("Content-Type", "application/octet-stream") + w.Header().Set("Content-Type", "application/octet-stream") readme := "vcsim generated support bundle" tw := tar.NewWriter(w)