Skip to content

Commit

Permalink
fix: Heal the broken Namespace API
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
akutz committed Dec 12, 2022
1 parent 22c4814 commit 1ad33d4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions govc/namespace/cluster/enable.go
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions govc/namespace/cluster/logs.go
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions govc/test/namespace.bats
Expand Up @@ -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"
Expand All @@ -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 \
Expand All @@ -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
}

Expand Down
14 changes: 9 additions & 5 deletions vapi/namespace/namespace.go
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vapi/namespace/simulator/simulator.go
Expand Up @@ -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)
Expand Down

0 comments on commit 1ad33d4

Please sign in to comment.