Skip to content

Commit

Permalink
Self review, test
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <[email protected]>
  • Loading branch information
Didainius committed Feb 12, 2025
1 parent ba72464 commit c377b0d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
11 changes: 5 additions & 6 deletions govcd/cci_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ const (
statePollInterval = 10 * time.Second
)

// CciClient
// CciClient exposes methods for operation on CCI endpoints
type CciClient struct {
VCDClient *VCDClient
}

// IsSupported checks if CCI is Supported on this system
func (cciClient *CciClient) IsSupported() bool {
return cciClient.VCDClient.Client.APIVCDMaxVersionIs(">= 40")
}

func (tpClient *CciClient) GetCciUrl(endpoint ...string) (*url.URL, error) {
path := fmt.Sprintf(ccitypes.CciKubernetesSubpath, tpClient.VCDClient.Client.VCDHREF.Scheme, tpClient.VCDClient.Client.VCDHREF.Host)
// GetCciUrl builds up CCI endpoints
func (cciClient *CciClient) GetCciUrl(endpoint ...string) (*url.URL, error) {
path := fmt.Sprintf(ccitypes.CciKubernetesSubpath, cciClient.VCDClient.Client.VCDHREF.Scheme, cciClient.VCDClient.Client.VCDHREF.Host)
path = path + strings.Join(endpoint, "")

return url.ParseRequestURI(path)
Expand Down Expand Up @@ -146,7 +148,6 @@ func (cciClient *CciClient) GetItem(urlRef *url.URL, params url.Values, outType

// HTTP 404: Not Found - include sentinel log message ErrorEntityNotFound so that errors can be
// checked with ContainsNotFound() and IsNotFound()

if resp.StatusCode == http.StatusNotFound {
err := ParseErr(types.BodyTypeJSON, resp, &ccitypes.CciApiError{})
closeErr := resp.Body.Close()
Expand Down Expand Up @@ -338,8 +339,6 @@ func (cciClient *CciClient) newCciRequest(params url.Values, method string, reqU
req.Header.Add("Authorization", "bearer "+client.VCDToken)
req.Header.Add("X-Vmware-Vcloud-Token-Type", "Bearer")
}
// Add the Accept header if apiVersion is specified

}

for k, v := range client.customHeader {
Expand Down
33 changes: 33 additions & 0 deletions govcd/cci_kube_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build functional || cci || ALL

package govcd

import (
"fmt"

. "gopkg.in/check.v1"
)

func (vcd *TestVCD) Test_KubeConfig(check *C) {
skipNonTm(vcd, check)
vcd.skipIfSysAdmin(check) // The test is running in Org user mode

cciClient := vcd.client.GetCciClient()
kubeCfg, kubeConfigValues, err := cciClient.GetKubeConfig(vcd.config.Tenants[0].SysOrg, "", "")
check.Assert(err, IsNil)
check.Assert(kubeCfg, NotNil)
check.Assert(kubeConfigValues, NotNil)

check.Assert(kubeConfigValues.ContextName, Equals, vcd.config.Tenants[0].SysOrg)
check.Assert(kubeConfigValues.ClusterName, Equals, fmt.Sprintf("%s:%s", vcd.config.Tenants[0].SysOrg, cciClient.VCDClient.Client.VCDHREF.Host))
check.Assert(kubeConfigValues.ClusterServer, Equals, fmt.Sprintf("%s://%s/%s", cciClient.VCDClient.Client.VCDHREF.Scheme, cciClient.VCDClient.Client.VCDHREF.Host, "cci/kubernetes"))
check.Assert(kubeConfigValues.UserName, Equals, fmt.Sprintf("%s:%s@%s", vcd.config.Tenants[0].SysOrg, vcd.config.Tenants[0].User, cciClient.VCDClient.Client.VCDHREF.Host))
check.Assert(kubeConfigValues.Token, NotNil)

check.Assert(len(kubeCfg.Clusters) == 1, Equals, true)
check.Assert(kubeCfg.Clusters[kubeConfigValues.ClusterName].Server, Equals, kubeConfigValues.ClusterServer)
check.Assert(len(kubeCfg.AuthInfos) == 1, Equals, true)
check.Assert(kubeCfg.AuthInfos[kubeConfigValues.UserName].Token, Not(Equals), "")
check.Assert(kubeCfg.Contexts[kubeConfigValues.ContextName].AuthInfo, Equals, kubeConfigValues.UserName)
check.Assert(kubeCfg.Contexts[kubeConfigValues.ContextName].Cluster, Equals, kubeConfigValues.ClusterName)
}

0 comments on commit c377b0d

Please sign in to comment.