Skip to content

Commit

Permalink
Merge branch 'devel' into css_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov committed Dec 4, 2024
2 parents 18daabc + 0696a5d commit f79fb55
Show file tree
Hide file tree
Showing 39 changed files with 1,231 additions and 606 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- opened
- edited
- synchronize
workflow_dispatch:
pull_request_target:
types: [ opened, synchronize ]

env:
GO_VERSION: '1.20'
Expand Down
52 changes: 52 additions & 0 deletions acceptance/openstack/apigw/v2/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,55 @@ func WaitForJob(c *golangsdk.ServiceClient, id string, secs int) error {
return false, nil
})
}

func TestGatewayFeaturesLifecycle(t *testing.T) {
client, err := clients.NewAPIGWClient()
th.AssertNoErr(t, err)

accInstanceName := "apig-do-not-delete"
gw, err := gateway.List(client, gateway.ListOpts{
InstanceName: accInstanceName,
})
th.AssertNoErr(t, err)
if len(gw) == 0 {
t.Skipf("Instance: %s, must exist for this test", accInstanceName)
}
gatewayID := gw[0].ID

t.Logf("Attempting to Get APIGW Gateway Features")
features, err := gateway.ListGatewayFeatures(client,
gateway.ListFeaturesOpts{GatewayID: gatewayID},
)
th.AssertNoErr(t, err)
if len(features) < 1 {
t.Error("no features found for selected Gateway")
}
t.Logf("Attempting to Configure APIGW Gateway Route Feature for: %s", gatewayID)
routeFeature, err := gateway.ConfigureFeature(client, gateway.FeatureOpts{
GatewayID: gatewayID,
Name: "route",
Enable: pointerto.Bool(true),
Config: "{\"user_routes\":[\"172.16.128.0/20\",\"172.16.0.0/20\"]}",
})
th.AssertNoErr(t, err)
th.AssertEquals(t, "{\"user_routes\":[\"172.16.128.0/20\",\"172.16.0.0/20\"]}", routeFeature.Config)

t.Logf("Attempting to Configure APIGW Gateway Ratelimit Feature for: %s", gatewayID)
rateLimitFeature, err := gateway.ConfigureFeature(client, gateway.FeatureOpts{
GatewayID: gatewayID,
Name: "ratelimit",
Enable: pointerto.Bool(true),
Config: "{\"api_limits\":300}",
})
th.AssertNoErr(t, err)
th.AssertEquals(t, "{\"api_limits\":300}", rateLimitFeature.Config)

// Not published !!!
// supported, err := gateway.ListSupportedGatewayFeatures(client,
// gateway.ListSupportedFeaturesOpts{GatewayID: gatewayID},
// )
// th.AssertNoErr(t, err)
// if len(supported) < 1 {
// t.Error("no features found for selected Gateway")
// }
}
16 changes: 8 additions & 8 deletions acceptance/openstack/cce/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"testing"

"github.com/opentelekomcloud/gophertelekomcloud"
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters"
Expand Down Expand Up @@ -44,14 +44,14 @@ func CreateCluster(t *testing.T, vpcID, subnetID string) string {
"kubernetes.io/cpuManagerPolicy": "static",
},
},
}).Extract()
})
th.AssertNoErr(t, err)

th.AssertNoErr(t, waitForClusterToActivate(client, cluster.Metadata.Id, 30*60))
return cluster.Metadata.Id
}

func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string, eniCidr string) string {
func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string, eniCidr string) *clusters.Clusters {
client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

Expand Down Expand Up @@ -82,17 +82,17 @@ func CreateTurboCluster(t *testing.T, vpcID, subnetID string, eniSubnetID string
},
KubernetesSvcIpRange: "10.247.0.0/16",
},
}).Extract()
})
th.AssertNoErr(t, err)

th.AssertNoErr(t, waitForClusterToActivate(client, cluster.Metadata.Id, 30*60))
return cluster.Metadata.Id
return cluster
}

func DeleteCluster(t *testing.T, clusterID string) {
client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)
err = clusters.DeleteWithOpts(client, clusterID, clusters.DeleteOpts{
err = clusters.Delete(client, clusterID, clusters.DeleteQueryParams{
DeleteEfs: "true",
DeleteObs: "true",
DeleteSfs: "true",
Expand All @@ -103,7 +103,7 @@ func DeleteCluster(t *testing.T, clusterID string) {

func waitForClusterToActivate(client *golangsdk.ServiceClient, id string, secs int) error {
return golangsdk.WaitFor(secs, func() (bool, error) {
cluster, err := clusters.Get(client, id).Extract()
cluster, err := clusters.Get(client, id)
if err != nil {
return false, err
}
Expand All @@ -119,7 +119,7 @@ func waitForClusterToActivate(client *golangsdk.ServiceClient, id string, secs i

func waitForClusterToDelete(client *golangsdk.ServiceClient, id string, secs int) error {
return golangsdk.WaitFor(secs, func() (bool, error) {
_, err := clusters.Get(client, id).Extract()
_, err := clusters.Get(client, id)
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
return true, nil
Expand Down
50 changes: 50 additions & 0 deletions acceptance/openstack/cce/v3/addnode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package v3

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/nodes"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestAddExistingNode(t *testing.T) {
vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
clusterID := clients.EnvOS.GetEnv("CLUSTER_ID")
serverID := clients.EnvOS.GetEnv("SERVER_ID")
sshKey := clients.EnvOS.GetEnv("KEYPAIR_NAME")
if vpcID == "" || subnetID == "" || clusterID == "" || sshKey == "" {
t.Skip("OS_VPC_ID, OS_NETWORK_ID, OS_KEYPAIR_NAME and OS_CLUSTER_ID are required for this test")
}
client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

nodeList, err := nodes.List(client, clusterID, nodes.ListOpts{})
th.AssertNoErr(t, err)
num_nodes := len(nodeList)

addNodeOpts := clusters.AddExistingNodeOpts{
APIVersion: "v3",
Kind: "List",
NodeList: []clusters.AddNode{
{
ServerID: serverID,
Spec: &clusters.ReinstallNodeSpec{
OS: "EulerOS 2.9",
Login: clusters.Login{
SSHKey: sshKey,
},
},
},
},
}

_, err = clusters.AddExistingNode(client, clusterID, addNodeOpts)
th.AssertNoErr(t, err)

nodeList, err = nodes.List(client, clusterID, nodes.ListOpts{})
th.AssertNoErr(t, err)
th.AssertEquals(t, num_nodes+1, len(nodeList))
}
61 changes: 36 additions & 25 deletions acceptance/openstack/cce/v3/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,50 @@ import (

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack/cce"
"github.com/stretchr/testify/suite"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/networking/v1/subnets"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

type testCluster struct {
suite.Suite
func TestListCluster(t *testing.T) {
client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

vpcID string
subnetID string
clusterID string
eniSubnetID string
eniCidr string
_, err = clusters.List(client, clusters.ListOpts{})
th.AssertNoErr(t, err)
}

func TestCluster(t *testing.T) {
suite.Run(t, new(testCluster))
}
vpcID := clients.EnvOS.GetEnv("VPC_ID")
if vpcID == "" {
t.Skip("OS_VPC_ID is required for this test")
}

clientNet, err := clients.NewNetworkV1Client()
th.AssertNoErr(t, err)

func (s *testCluster) SetupSuite() {
t := s.T()
s.vpcID = clients.EnvOS.GetEnv("VPC_ID")
s.subnetID = clients.EnvOS.GetEnv("NETWORK_ID")
s.eniSubnetID = clients.EnvOS.GetEnv("ENI_SUBNET_ID")
s.eniCidr = "10.0.0.0/14"
if s.vpcID == "" || s.subnetID == "" || s.eniSubnetID == "" {
t.Skip("OS_VPC_ID, OS_NETWORK_ID and OS_ENI_SUBNET_ID are required for this test")
listOpts := subnets.ListOpts{
VpcID: vpcID,
}
s.clusterID = cce.CreateTurboCluster(t, s.vpcID, s.subnetID, s.eniSubnetID, s.eniCidr)
}
subnetsList, err := subnets.List(clientNet, listOpts)
th.AssertNoErr(t, err)

if len(subnetsList) < 1 {
t.Skip("no subnets found in selected VPC")
}

client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

cluster := cce.CreateTurboCluster(t, vpcID, subnetsList[0].NetworkID, subnetsList[0].SubnetID, subnetsList[0].CIDR)

clusterID := cluster.Metadata.Id

clusterGet, err := clusters.Get(client, clusterID)
th.AssertNoErr(t, err)
th.AssertEquals(t, cluster.Metadata.Name, clusterGet.Metadata.Name)

func (s *testCluster) TearDownSuite() {
t := s.T()
if s.clusterID != "" {
cce.DeleteCluster(t, s.clusterID)
s.clusterID = ""
if clusterID != "" {
cce.DeleteCluster(t, clusterID)
}
}
45 changes: 11 additions & 34 deletions acceptance/openstack/cce/v3/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,29 @@ import (
"github.com/opentelekomcloud/gophertelekomcloud/openstack/cce/v3/clusters"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)

type testKubeConfig struct {
suite.Suite

routerID string
subnetID string
clusterID string
}

func TestKubeConfig(t *testing.T) {
suite.Run(t, new(testKubeConfig))
}

func (s *testKubeConfig) SetupSuite() {
t := s.T()
s.routerID = clients.EnvOS.GetEnv("VPC_ID", "ROUTER_ID")
s.subnetID = clients.EnvOS.GetEnv("NETWORK_ID")
if s.routerID == "" || s.subnetID == "" {
routerID := clients.EnvOS.GetEnv("VPC_ID", "ROUTER_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")
if routerID == "" || subnetID == "" {
t.Skip("OS_ROUTER_ID and OS_NETWORK_ID are required for this test")
}
s.clusterID = cce.CreateCluster(t, s.routerID, s.subnetID)
}

func (s *testKubeConfig) TearDownSuite() {
t := s.T()
if s.clusterID != "" {
cce.DeleteCluster(t, s.clusterID)
s.clusterID = ""
}
}

func (s *testKubeConfig) TestKubeConfigReading() {
t := s.T()

client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

kubeConfig, err := clusters.GetCert(client, s.clusterID).ExtractMap()
clusterID := cce.CreateCluster(t, routerID, subnetID)
t.Cleanup(func() {
cce.DeleteCluster(t, clusterID)
})

kubeConfig, err := clusters.GetCert(client, clusterID)
th.AssertNoErr(t, err)
require.NotEmpty(t, kubeConfig)

kubeConfigExp, err := clusters.GetCertWithExpiration(client, s.clusterID, clusters.ExpirationOpts{
kubeConfigExp, err := clusters.GetCertWithExpiration(client, clusterID, clusters.ExpirationOpts{
Duration: 5,
}).ExtractMap()
})
th.AssertNoErr(t, err)
require.NotEmpty(t, kubeConfigExp)
}
36 changes: 32 additions & 4 deletions acceptance/openstack/cce/v3/nodepool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v3

import (
"testing"
"time"

golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
Expand All @@ -11,13 +12,16 @@ import (
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func (s *testNodes) TestNodePoolLifecycle() {
t := s.T()
func TestNodePoolLifecycle(t *testing.T) {

clusterId := clients.EnvOS.GetEnv("CLUSTER_ID")
if clusterId == "" {
t.Skip("OS_CLUSTER_ID is required for this test")
}

client, err := clients.NewCceV3Client()
th.AssertNoErr(t, err)

clusterId := s.clusterID

kp := cce.CreateKeypair(t)
defer cce.DeleteKeypair(t, kp)

Expand Down Expand Up @@ -120,6 +124,30 @@ func (s *testNodes) TestNodePoolLifecycle() {
// th.AssertEquals(t, "false", pool.Spec.NodeTemplate.ExtendParam.IsAutoPay)
// th.AssertEquals(t, "false", pool.Spec.NodeTemplate.ExtendParam.IsAutoRenew)

updateOpts := nodepools.UpdateOpts{
Metadata: nodepools.UpdateMetaData{
Name: "nodepool-test-updated",
},
Spec: nodepools.UpdateSpec{
InitialNodeCount: 1,
NodeTemplate: nodepools.UpdateNodeTemplate{},
},
}
updatedPool, err := nodepools.Update(client, clusterId, nodeId, updateOpts).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, "nodepool-test-updated", updatedPool.Metadata.Name)
th.AssertNoErr(t, golangsdk.WaitFor(1800, func() (bool, error) {
n, err := nodepools.Get(client, clusterId, nodeId).Extract()
if err != nil {
return false, err
}
if n.Status.Phase == "" {
return true, nil
}
time.Sleep(10 * time.Second)
return false, nil
}))

th.AssertNoErr(t, nodepools.Delete(client, clusterId, nodeId).ExtractErr())

err = golangsdk.WaitFor(1800, func() (bool, error) {
Expand Down
Loading

0 comments on commit f79fb55

Please sign in to comment.