-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- This PR implements the upstream proposal at: crossplane/crossplane#3939 - Subpackages belonging to each API group is produced. An example is: provider-gcp-cloudplatform. - ProviderConfig, ProviderConfigUsage and StoreConfig are part of a config package named provider-gcp-config. - The monolith package (containing all the CRDs and associated controllers) is still produced. - Each produced package except for the monolith package has the `pkg.crossplane.io/provider-family` label in its package metadata. - Each service package except for the config package declares a dependency to the config package. Signed-off-by: Alper Rifat Ulucinar <[email protected]>
- Loading branch information
Showing
486 changed files
with
13,302 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
Copyright 2021 The Crossplane Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"gopkg.in/alecthomas/kingpin.v2" | ||
kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/leaderelection/resourcelock" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
|
||
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" | ||
xpcontroller "github.com/crossplane/crossplane-runtime/pkg/controller" | ||
"github.com/crossplane/crossplane-runtime/pkg/feature" | ||
"github.com/crossplane/crossplane-runtime/pkg/logging" | ||
"github.com/crossplane/crossplane-runtime/pkg/ratelimiter" | ||
"github.com/crossplane/crossplane-runtime/pkg/resource" | ||
|
||
tjcontroller "github.com/upbound/upjet/pkg/controller" | ||
"github.com/upbound/upjet/pkg/terraform" | ||
|
||
"github.com/upbound/provider-gcp/apis" | ||
"github.com/upbound/provider-gcp/apis/v1alpha1" | ||
"github.com/upbound/provider-gcp/config" | ||
"github.com/upbound/provider-gcp/internal/clients" | ||
"github.com/upbound/provider-gcp/internal/controller" | ||
"github.com/upbound/provider-gcp/internal/features" | ||
|
||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
) | ||
|
||
func main() { | ||
var ( | ||
app = kingpin.New(filepath.Base(os.Args[0]), "Terraform based Crossplane provider for GCP").DefaultEnvars() | ||
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool() | ||
syncInterval = app.Flag("sync", "Sync interval controls how often all resources will be double checked for drift.").Short('s').Default("1h").Duration() | ||
pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("10m").Duration() | ||
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool() | ||
maxReconcileRate = app.Flag("max-reconcile-rate", "The global maximum rate per second at which resources may checked for drift from the desired state.").Default("10").Int() | ||
pluginProcessTTL = app.Flag("provider-ttl", "TTL for the native plugin processes before they are replaced. Changing the default may increase memory consumption.").Default("100").Int() | ||
terraformVersion = app.Flag("terraform-version", "Terraform version.").Required().Envar("TERRAFORM_VERSION").String() | ||
nativeProviderSource = app.Flag("terraform-provider-source", "Terraform provider source.").Required().Envar("TERRAFORM_PROVIDER_SOURCE").String() | ||
providerVersion = app.Flag("terraform-provider-version", "Terraform provider version.").Required().Envar("TERRAFORM_PROVIDER_VERSION").String() | ||
nativeProviderPath = app.Flag("terraform-native-provider-path", "Terraform native provider path for shared execution.").Default("").Envar("TERRAFORM_NATIVE_PROVIDER_PATH").String() | ||
|
||
namespace = app.Flag("namespace", "Namespace used to set as default scope in default secret store config.").Default("crossplane-system").Envar("POD_NAMESPACE").String() | ||
enableExternalSecretStores = app.Flag("enable-external-secret-stores", "Enable support for ExternalSecretStores.").Default("false").Envar("ENABLE_EXTERNAL_SECRET_STORES").Bool() | ||
enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("false").Envar("ENABLE_MANAGEMENT_POLICIES").Bool() | ||
) | ||
|
||
kingpin.MustParse(app.Parse(os.Args[1:])) | ||
|
||
zl := zap.New(zap.UseDevMode(*debug)) | ||
log := logging.NewLogrLogger(zl.WithName("provider-gcp")) | ||
if *debug { | ||
// The controller-runtime runs with a no-op logger by default. It is | ||
// *very* verbose even at info level, so we only provide it a real | ||
// logger when we're running in debug mode. | ||
ctrl.SetLogger(zl) | ||
} | ||
|
||
log.Debug("Starting", "sync-interval", syncInterval.String(), | ||
"poll-interval", pollInterval.String(), "max-reconcile-rate", *maxReconcileRate) | ||
|
||
cfg, err := ctrl.GetConfig() | ||
kingpin.FatalIfError(err, "Cannot get API server rest config") | ||
|
||
mgr, err := ctrl.NewManager(ratelimiter.LimitRESTConfig(cfg, *maxReconcileRate), ctrl.Options{ | ||
LeaderElection: *leaderElection, | ||
LeaderElectionID: "crossplane-leader-election-provider-gcp", | ||
SyncPeriod: syncInterval, | ||
LeaderElectionResourceLock: resourcelock.LeasesResourceLock, | ||
LeaseDuration: func() *time.Duration { d := 60 * time.Second; return &d }(), | ||
RenewDeadline: func() *time.Duration { d := 50 * time.Second; return &d }(), | ||
}) | ||
kingpin.FatalIfError(err, "Cannot create controller manager") | ||
kingpin.FatalIfError(apis.AddToScheme(mgr.GetScheme()), "Cannot add GCP APIs to scheme") | ||
|
||
// if the native Terraform provider plugin's path is not configured via | ||
// the env. variable TERRAFORM_NATIVE_PROVIDER_PATH or | ||
// the `--terraform-native-provider-path` command-line option, | ||
// we do not use the shared gRPC server and default to the regular | ||
// Terraform CLI behaviour (of forking a plugin process per invocation). | ||
// This removes some complexity for setting up development environments. | ||
var scheduler terraform.ProviderScheduler = terraform.NewNoOpProviderScheduler() | ||
if len(*nativeProviderPath) != 0 { | ||
scheduler = terraform.NewSharedProviderScheduler(log, *pluginProcessTTL, terraform.WithNativeProviderPath(*nativeProviderPath), terraform.WithNativeProviderName("registry.terraform.io/"+*nativeProviderSource)) | ||
} | ||
|
||
o := tjcontroller.Options{ | ||
Options: xpcontroller.Options{ | ||
Logger: log, | ||
GlobalRateLimiter: ratelimiter.NewGlobal(*maxReconcileRate), | ||
PollInterval: *pollInterval, | ||
MaxConcurrentReconciles: *maxReconcileRate, | ||
Features: &feature.Flags{}, | ||
}, | ||
Provider: config.GetProvider(), | ||
WorkspaceStore: terraform.NewWorkspaceStore(log, terraform.WithDisableInit(len(*nativeProviderPath) != 0), terraform.WithProcessReportInterval(*pollInterval)), | ||
SetupFn: clients.TerraformSetupBuilder(*terraformVersion, *nativeProviderSource, *providerVersion, scheduler), | ||
} | ||
if *enableExternalSecretStores { | ||
o.SecretStoreConfigGVK = &v1alpha1.StoreConfigGroupVersionKind | ||
log.Info("Alpha feature enabled", "flag", features.EnableAlphaExternalSecretStores) | ||
|
||
// Ensure default store config exists. | ||
kingpin.FatalIfError(resource.Ignore(kerrors.IsAlreadyExists, mgr.GetClient().Create(context.Background(), &v1alpha1.StoreConfig{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "default", | ||
}, | ||
Spec: v1alpha1.StoreConfigSpec{ | ||
// NOTE(turkenh): We only set required spec and expect optional | ||
// ones to properly be initialized with CRD level default values. | ||
SecretStoreConfig: xpv1.SecretStoreConfig{ | ||
DefaultScope: *namespace, | ||
}, | ||
}, | ||
Status: v1alpha1.StoreConfigStatus{}, | ||
})), "cannot create default store config") | ||
} | ||
|
||
if *enableManagementPolicies { | ||
o.Features.Enable(features.EnableAlphaManagementPolicies) | ||
log.Info("Alpha feature enabled", "flag", features.EnableAlphaManagementPolicies) | ||
} | ||
|
||
kingpin.FatalIfError(controller.Setup_activedirectory(mgr, o), "Cannot setup GCP controllers") | ||
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager") | ||
} |
Oops, something went wrong.