Skip to content

Commit

Permalink
Move EKS clusterbuilder under capa
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Noble <[email protected]>
  • Loading branch information
AverageMarcus committed Apr 26, 2024
1 parent 70d7693 commit ca00840
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 54 deletions.
3 changes: 1 addition & 2 deletions cmd/standup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/giantswarm/cluster-standup-teardown/pkg/clusterbuilder/providers/capv"
"github.com/giantswarm/cluster-standup-teardown/pkg/clusterbuilder/providers/capvcd"
"github.com/giantswarm/cluster-standup-teardown/pkg/clusterbuilder/providers/capz"
"github.com/giantswarm/cluster-standup-teardown/pkg/clusterbuilder/providers/eks"
"github.com/giantswarm/cluster-standup-teardown/pkg/standup"
)

Expand Down Expand Up @@ -125,7 +124,7 @@ func run(cmd *cobra.Command, args []string) error {
cluster = clusterBuilder.NewClusterApp(clusterName, orgName, clusterValues, defaultAppValues).
WithAppVersions(clusterVersion, defaultAppVersion)
case application.ProviderEKS:
clusterBuilder := eks.ClusterBuilder{}
clusterBuilder := capa.ManagedClusterBuilder{}
cluster = clusterBuilder.NewClusterApp(clusterName, orgName, clusterValues, defaultAppValues).
WithAppVersions(clusterVersion, defaultAppVersion)
// As EKS has no control plane we only check for worker nodes being ready
Expand Down
43 changes: 0 additions & 43 deletions pkg/clusterbuilder/providers/capa/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package capa

import (
_ "embed"
"fmt"
"math/rand"

"github.com/giantswarm/cluster-standup-teardown/pkg/values"

Expand Down Expand Up @@ -42,44 +40,3 @@ func (c *ClusterBuilder) NewClusterApp(clusterName string, orgName string, clust
},
)
}

var (
//go:embed values/private-cluster_values.yaml
basePrivateClusterValues string
//go:embed values/private-default-apps_values.yaml
basePrivateDefaultAppsValues string
)

// PrivateClusterBuilder is the private CAPA ClusterBuilder
type PrivateClusterBuilder struct{}

// NewClusterApp builds a new private CAPA cluster App
func (c *PrivateClusterBuilder) NewClusterApp(clusterName string, orgName string, clusterValuesFile string, defaultAppsValuesFile string) *application.Cluster {
if clusterName == "" {
clusterName = utils.GenerateRandomName("t")
}
if orgName == "" {
orgName = utils.GenerateRandomName("t")
}

// WC CIDRs have to not overlap and be in the 10.225. - 10.255. range, so
// we select a random number in that range and set it as the second octet.
//nolint:gosec
randomOctet := rand.Intn(30) + 225
cidrOctet := fmt.Sprintf("%d", randomOctet)
templateValues := &application.TemplateValues{
ClusterName: clusterName,
Organization: orgName,
ExtraValues: map[string]string{
"CIDRSecondOctet": cidrOctet,
},
}

return application.NewClusterApp(clusterName, application.ProviderAWS).
WithOrg(organization.New(orgName)).
WithAppValues(
values.MustOverlayValues(basePrivateClusterValues, clusterValuesFile),
values.MustOverlayValues(basePrivateDefaultAppsValues, defaultAppsValuesFile),
templateValues,
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eks
package capa

import (
_ "embed"
Expand All @@ -11,17 +11,17 @@ import (
)

var (
//go:embed values/cluster_values.yaml
baseClusterValues string
//go:embed values/default-apps_values.yaml
baseDefaultAppsValues string
//go:embed values/managed-cluster_values.yaml
baseManagedClusterValues string
//go:embed values/managed-default-apps_values.yaml
baseManagedDefaultAppsValues string
)

// ClusterBuilder is the CAPA EKS ClusterBuilder
type ClusterBuilder struct{}
type ManagedClusterBuilder struct{}

// NewClusterApp builds a new CAPA EKS cluster App
func (c *ClusterBuilder) NewClusterApp(clusterName string, orgName string, clusterValuesFile string, defaultAppsValuesFile string) *application.Cluster {
func (c *ManagedClusterBuilder) NewClusterApp(clusterName string, orgName string, clusterValuesFile string, defaultAppsValuesFile string) *application.Cluster {
if clusterName == "" {
clusterName = utils.GenerateRandomName("t")
}
Expand All @@ -32,8 +32,8 @@ func (c *ClusterBuilder) NewClusterApp(clusterName string, orgName string, clust
return application.NewClusterApp(clusterName, application.ProviderEKS).
WithOrg(organization.New(orgName)).
WithAppValues(
values.MustOverlayValues(baseClusterValues, clusterValuesFile),
values.MustOverlayValues(baseDefaultAppsValues, defaultAppsValuesFile),
values.MustOverlayValues(baseManagedClusterValues, clusterValuesFile),
values.MustOverlayValues(baseManagedDefaultAppsValues, defaultAppsValuesFile),
&application.TemplateValues{
ClusterName: clusterName,
Organization: orgName,
Expand Down
53 changes: 53 additions & 0 deletions pkg/clusterbuilder/providers/capa/private_cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package capa

import (
_ "embed"
"fmt"
"math/rand"

"github.com/giantswarm/cluster-standup-teardown/pkg/values"
"github.com/giantswarm/clustertest/pkg/application"
"github.com/giantswarm/clustertest/pkg/organization"
"github.com/giantswarm/clustertest/pkg/utils"
)

var (
//go:embed values/private-cluster_values.yaml
basePrivateClusterValues string
//go:embed values/private-default-apps_values.yaml
basePrivateDefaultAppsValues string
)

// PrivateClusterBuilder is the private CAPA ClusterBuilder
type PrivateClusterBuilder struct{}

// NewClusterApp builds a new private CAPA cluster App
func (c *PrivateClusterBuilder) NewClusterApp(clusterName string, orgName string, clusterValuesFile string, defaultAppsValuesFile string) *application.Cluster {
if clusterName == "" {
clusterName = utils.GenerateRandomName("t")
}
if orgName == "" {
orgName = utils.GenerateRandomName("t")
}

// WC CIDRs have to not overlap and be in the 10.225. - 10.255. range, so
// we select a random number in that range and set it as the second octet.
//nolint:gosec
randomOctet := rand.Intn(30) + 225
cidrOctet := fmt.Sprintf("%d", randomOctet)
templateValues := &application.TemplateValues{
ClusterName: clusterName,
Organization: orgName,
ExtraValues: map[string]string{
"CIDRSecondOctet": cidrOctet,
},
}

return application.NewClusterApp(clusterName, application.ProviderAWS).
WithOrg(organization.New(orgName)).
WithAppValues(
values.MustOverlayValues(basePrivateClusterValues, clusterValuesFile),
values.MustOverlayValues(basePrivateDefaultAppsValues, defaultAppsValuesFile),
templateValues,
)
}

0 comments on commit ca00840

Please sign in to comment.