Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable PKE on Azure and AWS #3637

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions charts/pipeline/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ configuration:
# default: true

# Distribution settings
# distribution:
distribution:

# eks:
# # EKS Cloud Formation template location
Expand All @@ -190,12 +190,15 @@ configuration:
# # Enable create & update of EKS addons like coredns
# enableAddons: false

# pke:
# amazon:
pke:
amazon:
enabled: true
# globalRegion: us-east-1
# defaultImages: {}
# defaultNetworkProvider: "cilium"
# defaultNodeVolumeSize: 0 # GiB, 0/fallback: max(50, AMISize)
azure:
enabled: true

# Database configuration
database:
Expand Down
2 changes: 2 additions & 0 deletions cmd/pipeline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func main() {
clusterCreators := api.ClusterCreators{
PKEOnAzure: azurePKEDriver.MakeClusterCreator(
azurePKEDriver.ClusterCreatorConfig{
Enabled: config.Distribution.PKE.Azure.Enabled,
OIDCIssuerURL: config.Auth.OIDC.Issuer,
PipelineExternalURL: externalBaseURL,
PipelineExternalURLInsecure: externalURLInsecure,
Expand Down Expand Up @@ -672,6 +673,7 @@ func main() {
dynamicClientFactory,
unifiedHelmReleaser,
config.Auth,
config.Distribution,
clusterAuthService,
)

Expand Down
9 changes: 6 additions & 3 deletions config/config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ dex:
# # Default Amazon region
# defaultRegion: "us-west-1"

#distribution:
distribution:
# eks:
#
# # EKS Cloud Formation template location
Expand All @@ -417,12 +417,15 @@ dex:
# # Enable create & update of EKS addons like coredns
# enableAddons: false
#
# pke:
# amazon:
pke:
amazon:
enabled: true
# globalRegion: us-east-1
# defaultImages: {}
# defaultNetworkProvider: "cilium"
# defaultNodeVolumeSize: 0 # GiB, 0/fallback: max(50, AMISize)
azure:
enabled: true

cloudinfo:
# Format: {baseUrl}/api/v1
Expand Down
57 changes: 33 additions & 24 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,7 @@ type Config struct {
APICa string
}

Distribution struct {
EKS struct {
TemplateLocation string
DefaultNodeVolumeEncryption *struct {
Enabled bool
EncryptionKeyARN string
}
DefaultNodeVolumeSize int
ExposeAdminKubeconfig bool
SSH struct {
Generate bool
}
EnableAddons bool
}

PKE struct {
Amazon struct {
GlobalRegion string
DefaultImages map[string]string
DefaultNetworkProvider string
DefaultNodeVolumeSize int
}
}
}
Distribution DistributionConfig

Helm helm.Config

Expand Down Expand Up @@ -521,6 +498,35 @@ func (c TelemetryConfig) Validate() error {
return err
}

type DistributionConfig struct {
EKS struct {
TemplateLocation string
DefaultNodeVolumeEncryption *struct {
Enabled bool
EncryptionKeyARN string
}
DefaultNodeVolumeSize int
ExposeAdminKubeconfig bool
SSH struct {
Generate bool
}
EnableAddons bool
}

PKE struct {
Amazon struct {
Enabled bool
GlobalRegion string
DefaultImages map[string]string
DefaultNetworkProvider string
DefaultNodeVolumeSize int
}
Azure struct {
Enabled bool
}
}
}

// Configure configures some defaults in the Viper instance.
func Configure(v *viper.Viper, p *pflag.FlagSet) {
// Log configuration
Expand Down Expand Up @@ -877,11 +883,14 @@ traefik:
v.SetDefault("distribution::eks::ssh::generate", true)
v.SetDefault("distribution::eks::enableAddons", false)

v.SetDefault("distribution::pke::amazon::enabled", true)
v.SetDefault("distribution::pke::amazon::globalRegion", "us-east-1")
v.SetDefault("distribution::pke::amazon::defaultImages", map[string]string{})
v.SetDefault("distribution::pke::amazon::defaultNetworkProvider", "cilium")
v.SetDefault("distribution::pke::amazon::defaultNodeVolumeSize", 0)

v.SetDefault("distribution::pke::azure::enabled", true)

v.SetDefault("cloudinfo::endpoint", "")

v.SetDefault("secret::tls::defaultValidity", "8760h") // 1 year
Expand Down
1 change: 1 addition & 0 deletions internal/providers/azure/pke/driver/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//pkg/cluster",
"//pkg/cluster/pke",
"//pkg/common",
"//pkg/errors",
"//pkg/k8sclient",
"//pkg/providers/azure",
"//src/auth",
Expand Down
7 changes: 7 additions & 0 deletions internal/providers/azure/pke/driver/cluster_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/banzaicloud/pipeline/internal/secret/secrettype"
pkgCluster "github.com/banzaicloud/pipeline/pkg/cluster"
pkgPKE "github.com/banzaicloud/pipeline/pkg/cluster/pke"
pkgErrors "github.com/banzaicloud/pipeline/pkg/errors"
pkgAzure "github.com/banzaicloud/pipeline/pkg/providers/azure"
"github.com/banzaicloud/pipeline/src/auth"
"github.com/banzaicloud/pipeline/src/cluster"
Expand Down Expand Up @@ -86,6 +87,7 @@ type ClusterCreatorSecretStore interface {
}

type ClusterCreatorConfig struct {
Enabled bool
OIDCIssuerURL string
PipelineExternalURL string
PipelineExternalURLInsecure bool
Expand Down Expand Up @@ -157,6 +159,11 @@ type ClusterCreationParams struct {

// Create
func (cc ClusterCreator) Create(ctx context.Context, params ClusterCreationParams) (cl pke.Cluster, err error) {
if !cc.config.Enabled {
err = pkgErrors.ErrorNotSupportedDistributionType
return
}

sir, err := cc.secrets.Get(params.OrganizationID, params.SecretID)
if err = errors.WrapIf(err, "failed to get secret"); err != nil {
return
Expand Down
1 change: 1 addition & 0 deletions src/api/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//internal/cluster/endpoints",
"//internal/cluster/oidc",
"//internal/cluster/resourcesummary",
"//internal/cmd",
"//internal/common",
"//internal/global",
"//internal/helm",
Expand Down
4 changes: 4 additions & 0 deletions src/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/banzaicloud/pipeline/internal/cluster/clusteradapter"
eksdriver "github.com/banzaicloud/pipeline/internal/cluster/distribution/eks/eksprovider/driver"
"github.com/banzaicloud/pipeline/internal/cluster/resourcesummary"
"github.com/banzaicloud/pipeline/internal/cmd"
"github.com/banzaicloud/pipeline/internal/global"
azureDriver "github.com/banzaicloud/pipeline/internal/providers/azure/pke/driver"
vsphereDriver "github.com/banzaicloud/pipeline/internal/providers/vsphere/pke/driver"
Expand Down Expand Up @@ -63,6 +64,7 @@ type ClusterAPI struct {

helmService cluster.HelmService
authConfig auth.Config
distributionConfig cmd.DistributionConfig
clientSecretGetter clusterAuth.ClusterClientSecretGetter
}

Expand Down Expand Up @@ -97,6 +99,7 @@ func NewClusterAPI(
clientFactory common.DynamicClientFactory,
helmService cluster.HelmService,
authConfig auth.Config,
distributionConfig cmd.DistributionConfig,
clientSecretGetter clusterAuth.ClusterClientSecretGetter,
) *ClusterAPI {
return &ClusterAPI{
Expand All @@ -112,6 +115,7 @@ func NewClusterAPI(
clientFactory: clientFactory,
helmService: helmService,
authConfig: authConfig,
distributionConfig: distributionConfig,
clientSecretGetter: clientSecretGetter,
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/api/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net/http"
"strings"

"emperror.dev/errors"
"github.com/gin-gonic/gin"
Expand All @@ -28,6 +29,7 @@ import (
ginutils "github.com/banzaicloud/pipeline/internal/platform/gin/utils"
pkgCluster "github.com/banzaicloud/pipeline/pkg/cluster"
pkgCommon "github.com/banzaicloud/pipeline/pkg/common"
pkgErrors "github.com/banzaicloud/pipeline/pkg/errors"
clusterAPI "github.com/banzaicloud/pipeline/src/api/cluster"
"github.com/banzaicloud/pipeline/src/auth"
"github.com/banzaicloud/pipeline/src/cluster"
Expand Down Expand Up @@ -262,6 +264,14 @@ func (a *ClusterAPI) createCluster(
}
}

if strings.HasPrefix(commonCluster.GetDistribution(), pkgCluster.PKE) && commonCluster.GetCloud() == pkgCluster.Amazon && !a.distributionConfig.PKE.Amazon.Enabled {
return nil, &pkgCommon.ErrorResponse{
Code: http.StatusBadRequest,
Message: pkgErrors.ErrorNotSupportedDistributionType.Error(),
Error: pkgErrors.ErrorNotSupportedDistributionType.Error(),
}
}

if _, ok := commonCluster.(*cluster.EKSCluster); ok {
commonCluster, err = a.clusterCreators.EKSAmazon.CreateCluster(ctx, commonCluster, createClusterRequest, organizationID, userID)
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package api
import (
"github.com/pkg/errors"

pkgErrors "github.com/banzaicloud/pipeline/pkg/errors"
"github.com/banzaicloud/pipeline/src/secret"
)

Expand All @@ -34,6 +35,8 @@ func isInvalid(err error) bool {
switch err {
case secret.ErrSecretNotExists:
return true
case pkgErrors.ErrorNotSupportedDistributionType:
return true
}

switch err.(type) {
Expand Down