소스 검색

Merge branch 'master' into capi

Stefan McShane 3 년 전
부모
커밋
0482705df0

+ 1 - 0
api/server/handlers/credentials/get_credentials_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package credentials

+ 1 - 0
api/server/handlers/credentials/get_credentials_ee.go

@@ -1,3 +1,4 @@
+//go:build ee
 // +build ee
 
 package credentials

+ 1 - 0
api/server/handlers/invite/invite_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package invite

+ 1 - 0
api/server/handlers/invite/invite_ee.go

@@ -1,3 +1,4 @@
+//go:build ee
 // +build ee
 
 package invite

+ 1 - 0
api/server/shared/config/loader/init_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package loader

+ 10 - 10
api/types/integrations.go

@@ -5,17 +5,17 @@ package types
 // auth mechanisms. For example, a GKE integration can have both an "oauth" mechanism
 // and a "gcp" mechanism:
 //
-// PorterIntegration{
-// 	AuthMechanism: "oauth",
-// 	Category: "cluster",
-// 	Service: GKE,
-// }
+//	PorterIntegration{
+//		AuthMechanism: "oauth",
+//		Category: "cluster",
+//		Service: GKE,
+//	}
 //
-// PorterIntegration{
-// 	AuthMechanism: "gcp",
-// 	Category: "cluster",
-// 	Service: GKE,
-// }
+//	PorterIntegration{
+//		AuthMechanism: "gcp",
+//		Category: "cluster",
+//		Service: GKE,
+//	}
 type PorterIntegration struct {
 	AuthMechanism string `json:"auth_mechanism"`
 	Category      string `json:"category"`

+ 11 - 1
cli/cmd/config/config.go

@@ -199,14 +199,24 @@ func (c *CLIConfig) SetHost(host string) error {
 	host = strings.TrimRight(host, "/")
 
 	viper.Set("host", host)
-	color.New(color.FgGreen).Printf("Set the current host as %s\n", host)
+
+	// let us clear the project ID, cluster ID, and token when we reset a host
+	viper.Set("project", 0)
+	viper.Set("cluster", 0)
+	viper.Set("token", "")
+
 	err := viper.WriteConfig()
 
 	if err != nil {
 		return err
 	}
 
+	color.New(color.FgGreen).Printf("Set the current host as %s\n", host)
+
 	config.Host = host
+	config.Project = 0
+	config.Cluster = 0
+	config.Token = ""
 
 	return nil
 }

+ 4 - 4
cli/cmd/deploy/deploy.go

@@ -153,10 +153,10 @@ type GetBuildEnvOpts struct {
 // GetBuildEnv retrieves the build env from the release config and returns it.
 //
 // It returns a flattened map of all environment variables including:
-//    1. container.env.normal from the release config
-//    2. container.env.build from the release config
-//    3. container.env.synced from the release config
-//    4. any additional env var that was passed into the DeployAgent as opts.SharedOpts.AdditionalEnv
+//  1. container.env.normal from the release config
+//  2. container.env.build from the release config
+//  3. container.env.synced from the release config
+//  4. any additional env var that was passed into the DeployAgent as opts.SharedOpts.AdditionalEnv
 func (d *DeployAgent) GetBuildEnv(opts *GetBuildEnvOpts) (map[string]string, error) {
 	conf := d.Release.Config
 

+ 6 - 7
cli/cmd/run.go

@@ -15,7 +15,6 @@ import (
 	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/spf13/cobra"
 	batchv1 "k8s.io/api/batch/v1"
-	batchv1beta1 "k8s.io/api/batch/v1beta1"
 	v1 "k8s.io/api/core/v1"
 	rbacv1 "k8s.io/api/rbac/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -573,7 +572,7 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 	}
 
 	for _, namespace := range namespaces.Items {
-		cronJobs, err := config.Clientset.BatchV1beta1().CronJobs(namespace.Name).List(
+		cronJobs, err := config.Clientset.BatchV1().CronJobs(namespace.Name).List(
 			context.Background(), metav1.ListOptions{},
 		)
 		if err != nil {
@@ -589,7 +588,7 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 		} else {
 			for _, cronJob := range cronJobs.Items {
 				if cronJob.Name == "porter-ephemeral-pod-deletion-cronjob" {
-					err = config.Clientset.BatchV1beta1().CronJobs(namespace.Name).Delete(
+					err = config.Clientset.BatchV1().CronJobs(namespace.Name).Delete(
 						context.Background(), cronJob.Name, metav1.DeleteOptions{},
 					)
 					if err != nil {
@@ -602,13 +601,13 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 
 	// create the cronjob
 
-	cronJob := &batchv1beta1.CronJob{
+	cronJob := &batchv1.CronJob{
 		ObjectMeta: metav1.ObjectMeta{
 			Name: "porter-ephemeral-pod-deletion-cronjob",
 		},
-		Spec: batchv1beta1.CronJobSpec{
+		Spec: batchv1.CronJobSpec{
 			Schedule: "0 * * * *",
-			JobTemplate: batchv1beta1.JobTemplateSpec{
+			JobTemplate: batchv1.JobTemplateSpec{
 				Spec: batchv1.JobSpec{
 					Template: v1.PodTemplateSpec{
 						Spec: v1.PodSpec{
@@ -628,7 +627,7 @@ func checkForPodDeletionCronJob(config *PorterRunSharedConfig) error {
 			},
 		},
 	}
-	_, err = config.Clientset.BatchV1beta1().CronJobs("default").Create(
+	_, err = config.Clientset.BatchV1().CronJobs("default").Create(
 		context.Background(), cronJob, metav1.CreateOptions{},
 	)
 	if err != nil {

+ 1 - 1
cli/cmd/utils/close.go

@@ -9,7 +9,7 @@ import (
 )
 
 func closeHandler(closer func() error) {
-	sig := make(chan os.Signal)
+	sig := make(chan os.Signal, 1)
 	signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
 	go func() {
 		<-sig

+ 1 - 0
cmd/migrate/migrate_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package main

+ 1 - 0
cmd/migrate/migrate_ee.go

@@ -1,3 +1,4 @@
+//go:build ee
 // +build ee
 
 package main

+ 2 - 2
internal/analytics/segment.go

@@ -59,8 +59,8 @@ func (c *AnalyticsSegment) Identify(identifier segmentIdentifier) error {
 	return err
 }
 
-//	Superset of segment client track function, this will accept analytics defined tracks only
-//	and will log an error if the client is not initialized
+// Superset of segment client track function, this will accept analytics defined tracks only
+// and will log an error if the client is not initialized
 func (c *AnalyticsSegment) Track(track segmentTrack) error {
 	if !c.isEnabled {
 		c.logger.Error().Msg("Analytics not enabled")

+ 2 - 3
internal/kubernetes/agent.go

@@ -26,7 +26,6 @@ import (
 	"github.com/porter-dev/porter/internal/helm/grapher"
 	appsv1 "k8s.io/api/apps/v1"
 	batchv1 "k8s.io/api/batch/v1"
-	batchv1beta1 "k8s.io/api/batch/v1beta1"
 	v1 "k8s.io/api/core/v1"
 	v1beta1 "k8s.io/api/extensions/v1beta1"
 	netv1 "k8s.io/api/networking/v1"
@@ -1080,8 +1079,8 @@ func (a *Agent) GetJob(c grapher.Object) (*batchv1.Job, error) {
 }
 
 // GetCronJob gets the CronJob by name and namespace
-func (a *Agent) GetCronJob(c grapher.Object) (*batchv1beta1.CronJob, error) {
-	res, err := a.Clientset.BatchV1beta1().CronJobs(c.Namespace).Get(
+func (a *Agent) GetCronJob(c grapher.Object) (*batchv1.CronJob, error) {
+	res, err := a.Clientset.BatchV1().CronJobs(c.Namespace).Get(
 		context.TODO(),
 		c.Name,
 		metav1.GetOptions{},

+ 0 - 1
internal/kubernetes/kubeconfig.go

@@ -111,7 +111,6 @@ func GetRawConfigFromBytes(kubeconfig []byte) (*api.Config, error) {
 // (3) If a bearer token exists, uses bearer token auth mechanism
 // (4) If a username/password exist, uses basic auth mechanism
 // (5) Otherwise, the config gets skipped
-//
 func parseAuthInfoForResolvers(authInfo *api.AuthInfo) (authMechanism models.ClusterAuth, resolvers []models.ClusterResolver) {
 	resolvers = make([]models.ClusterResolver, 0)
 

+ 1 - 0
internal/usage/limit_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package usage

+ 1 - 0
internal/usage/limit_ee.go

@@ -1,3 +1,4 @@
+//go:build ee
 // +build ee
 
 package usage

+ 1 - 0
provisioner/server/config/init_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package config

+ 1 - 0
provisioner/server/config/init_ee.go

@@ -1,3 +1,4 @@
+//go:build ee
 // +build ee
 
 package config

+ 1 - 0
provisioner/server/handlers/credentials/get_credentials_ce.go

@@ -1,3 +1,4 @@
+//go:build !ee
 // +build !ee
 
 package credentials

+ 9 - 7
workers/jobs/helm_revisions_count_tracker.go

@@ -60,6 +60,7 @@ type helmRevisionsCountTracker struct {
 	awsRegion          string
 	s3BucketName       string
 	encryptionKey      *[32]byte
+	revisionsCount     int
 }
 
 // HelmRevisionsCountTrackerOpts holds the options required to run this job
@@ -74,6 +75,7 @@ type HelmRevisionsCountTrackerOpts struct {
 	AWSRegion          string
 	S3BucketName       string
 	EncryptionKey      string
+	RevisionsCount     int
 }
 
 func NewHelmRevisionsCountTracker(
@@ -115,7 +117,7 @@ func NewHelmRevisionsCountTracker(
 	return &helmRevisionsCountTracker{
 		enqueueTime, db, repo, doConf, opts.DBConf, credBackend,
 		opts.AWSAccessKeyID, opts.AWSSecretAccessKey, opts.AWSRegion,
-		opts.S3BucketName, &s3Key,
+		opts.S3BucketName, &s3Key, opts.RevisionsCount,
 	}, nil
 }
 
@@ -237,19 +239,19 @@ func (t *helmRevisionsCountTracker) Run() error {
 							continue
 						}
 
-						if len(revisions) <= 20 {
-							log.Printf("release %s of namespace %s in cluster ID %d has <= 20 revisions. "+
-								"skipping release...", rel.Name, ns.Name, cluster.ID)
+						if len(revisions) <= t.revisionsCount {
+							log.Printf("release %s of namespace %s in cluster ID %d has <= %d revisions. "+
+								"skipping release...", t.revisionsCount, rel.Name, ns.Name, cluster.ID)
 							continue
 						}
 
-						log.Printf("release %s of namespace %s in cluster ID %d has more than 20 revisions. attempting to "+
-							"delete the older ones.", rel.Name, ns.Name, cluster.ID)
+						log.Printf("release %s of namespace %s in cluster ID %d has more than %d revisions. attempting to "+
+							"delete the older ones.", t.revisionsCount, rel.Name, ns.Name, cluster.ID)
 
 						// sort revisions from newest to oldest
 						releaseutil.Reverse(revisions, releaseutil.SortByRevision)
 
-						for i := 20; i < len(revisions); i += 1 {
+						for i := t.revisionsCount; i < len(revisions); i += 1 {
 							rev := revisions[i]
 
 							// store the revision in the s3 bucket before deleting it

+ 3 - 0
workers/main.go

@@ -56,6 +56,8 @@ type EnvConf struct {
 	LegacyProjectIDs []uint `env:"LEGACY_PROJECT_IDS"`
 
 	Port uint `env:"PORT,default=3000"`
+
+	RevisionsCount int `env:"REVISIONS_COUNT,default=20"`
 }
 
 func main() {
@@ -204,6 +206,7 @@ func getJob(id string, input map[string]interface{}) worker.Job {
 			AWSRegion:          envDecoder.AWSRegion,
 			S3BucketName:       envDecoder.S3BucketName,
 			EncryptionKey:      envDecoder.EncryptionKey,
+			RevisionsCount:     envDecoder.RevisionsCount,
 		})
 
 		if err != nil {