Skip to content

Commit

Permalink
Bump client-go to 1.18, including context
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Apr 4, 2020
1 parent f5b4bbf commit 7c724a6
Show file tree
Hide file tree
Showing 25 changed files with 135 additions and 384 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.12.14"
go-version: "1.14.1"
- name: setup goenv
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tagged-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.12.14"
go-version: "1.14.1"
- name: setup goenv
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
run: git fetch --prune --unshallow
- uses: actions/setup-go@v1
with:
go-version: "1.12.14"
go-version: "1.14.1"
- uses: azure/docker-login@v1
with:
username: schemaherodeploy
Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

func main() {
Expand Down
23 changes: 9 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,32 @@ module github.com/schemahero/schemahero
go 1.12

require (
github.com/Azure/go-autorest v11.1.2+incompatible // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/go-sql-driver/mysql v1.4.1
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/lib/pq v1.1.1
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/onsi/gomega v1.7.0
github.com/onsi/gomega v1.8.1
github.com/pkg/errors v0.8.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf
github.com/ventu-io/go-shortid v0.0.0-20171029131806-771a37caa5cf
github.com/xo/dburl v0.0.0-20190203050942-98997a05b24f
go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
gopkg.in/square/go-jose.v2 v2.3.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e // indirect
gopkg.in/yaml.v2 v2.2.8
k8s.io/api v0.18.0
k8s.io/apiextensions-apiserver v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/cli-runtime v0.17.0
k8s.io/cli-runtime v0.18.0
k8s.io/client-go v0.18.0
k8s.io/code-generator v0.18.1-beta.0 // indirect
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-tools v0.2.8 // indirect
sigs.k8s.io/controller-runtime v0.5.1-0.20200402191424-df180accb901
sigs.k8s.io/structured-merge-diff v1.0.1-0.20191108220359-b1b620dd3f06 // indirect

)

replace github.com/appscode/jsonpatch => github.com/gomodules/jsonpatch v2.0.1+incompatible



302 changes: 16 additions & 286 deletions go.sum

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions pkg/cli/schemaherokubectlcli/approve_migration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schemaherokubectlcli

import (
"context"
"fmt"
"time"

Expand All @@ -27,6 +28,7 @@ func ApproveMigrationCmd() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
ctx := context.Background()
migrationName := args[0]

cfg, err := config.GetConfig()
Expand All @@ -47,7 +49,7 @@ func ApproveMigrationCmd() *cobra.Command {
namespaceNames := []string{}

if viper.GetBool("all-namespaces") {
namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -64,7 +66,7 @@ func ApproveMigrationCmd() *cobra.Command {
}

for _, namespaceName := range namespaceNames {
migration, err := schemasClient.Migrations(namespaceName).Get(migrationName, metav1.GetOptions{})
migration, err := schemasClient.Migrations(namespaceName).Get(ctx, migrationName, metav1.GetOptions{})
if kuberneteserrors.IsNotFound(err) {
// continue to the next namespace
continue
Expand All @@ -74,7 +76,7 @@ func ApproveMigrationCmd() *cobra.Command {
}

migration.Status.ApprovedAt = time.Now().Unix()
if _, err := schemasClient.Migrations(namespaceName).Update(migration); err != nil {
if _, err := schemasClient.Migrations(namespaceName).Update(ctx, migration, metav1.UpdateOptions{}); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/cli/schemaherokubectlcli/describe_migration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schemaherokubectlcli

import (
"context"
"fmt"
"time"

Expand All @@ -27,6 +28,7 @@ func DescribeMigrationCmd() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
ctx := context.Background()
migrationName := args[0]

cfg, err := config.GetConfig()
Expand All @@ -47,7 +49,7 @@ func DescribeMigrationCmd() *cobra.Command {
namespaceNames := []string{}

if viper.GetBool("all-namespaces") {
namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -64,7 +66,7 @@ func DescribeMigrationCmd() *cobra.Command {
}

for _, namespaceName := range namespaceNames {
foundMigration, err := schemasClient.Migrations(namespaceName).Get(migrationName, metav1.GetOptions{})
foundMigration, err := schemasClient.Migrations(namespaceName).Get(ctx, migrationName, metav1.GetOptions{})
if kuberneteserrors.IsNotFound(err) {
// next namespace
continue
Expand Down
7 changes: 5 additions & 2 deletions pkg/cli/schemaherokubectlcli/get_databases.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schemaherokubectlcli

import (
"context"
"fmt"
"os"
"text/tabwriter"
Expand All @@ -24,6 +25,8 @@ func GetDatabasesCmd() *cobra.Command {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()

cfg, err := config.GetConfig()
if err != nil {
return err
Expand All @@ -39,15 +42,15 @@ func GetDatabasesCmd() *cobra.Command {
return err
}

namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}

matchingDatabases := []databasesv1alpha3.Database{}

for _, namespace := range namespaces.Items {
databases, err := databasesClient.Databases(namespace.Name).List(metav1.ListOptions{})
databases, err := databasesClient.Databases(namespace.Name).List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/cli/schemaherokubectlcli/get_migrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schemaherokubectlcli

import (
"context"
"fmt"
"os"
"text/tabwriter"
Expand All @@ -26,6 +27,8 @@ func GetMigrationsCmd() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
ctx := context.Background()

databaseNameFilter := v.GetString("database")

cfg, err := config.GetConfig()
Expand All @@ -46,7 +49,7 @@ func GetMigrationsCmd() *cobra.Command {
namespaceNames := []string{}

if viper.GetBool("all-namespaces") {
namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -64,7 +67,7 @@ func GetMigrationsCmd() *cobra.Command {

matchingMigrations := []schemasv1alpha3.Migration{}
for _, namespaceName := range namespaceNames {
migrations, err := schemasClient.Migrations(namespaceName).List(metav1.ListOptions{})
migrations, err := schemasClient.Migrations(namespaceName).List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -75,7 +78,7 @@ func GetMigrationsCmd() *cobra.Command {
continue
}

table, err := schemasClient.Tables(migration.Spec.TableNamespace).Get(migration.Spec.TableName, metav1.GetOptions{})
table, err := schemasClient.Tables(migration.Spec.TableNamespace).Get(ctx, migration.Spec.TableName, metav1.GetOptions{})
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/cli/schemaherokubectlcli/get_tables.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schemaherokubectlcli

import (
"context"
"fmt"
"os"
"text/tabwriter"
Expand All @@ -25,6 +26,8 @@ func GetTablesCmd() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
ctx := context.Background()

databaseNameFilter := v.GetString("database")

cfg, err := config.GetConfig()
Expand All @@ -42,15 +45,15 @@ func GetTablesCmd() *cobra.Command {
return err
}

namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{})
namespaces, err := client.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return err
}

matchingTables := []schemasv1alpha3.Table{}

for _, namespace := range namespaces.Items {
tables, err := schemasClient.Tables(namespace.Name).List(metav1.ListOptions{})
tables, err := schemasClient.Tables(namespace.Name).List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/controller/migration/lookup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package migration

import (
"context"

"github.com/pkg/errors"
databasesv1alpha3 "github.com/schemahero/schemahero/pkg/apis/databases/v1alpha3"
schemasv1alpha3 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha3"
Expand All @@ -10,7 +12,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

func tableFromMigration(migration *schemasv1alpha3.Migration) (*schemasv1alpha3.Table, error) {
func tableFromMigration(ctx context.Context, migration *schemasv1alpha3.Migration) (*schemasv1alpha3.Table, error) {
cfg, err := config.GetConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to get config")
Expand All @@ -21,15 +23,15 @@ func tableFromMigration(migration *schemasv1alpha3.Migration) (*schemasv1alpha3.
return nil, errors.Wrap(err, "failed to create schemas client")
}

table, err := schemasClient.Tables(migration.Spec.TableNamespace).Get(migration.Spec.TableName, metav1.GetOptions{})
table, err := schemasClient.Tables(migration.Spec.TableNamespace).Get(ctx, migration.Spec.TableName, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to get table")
}

return table, nil
}

func databaseFromTable(table *schemasv1alpha3.Table) (*databasesv1alpha3.Database, error) {
func databaseFromTable(ctx context.Context, table *schemasv1alpha3.Table) (*databasesv1alpha3.Database, error) {
cfg, err := config.GetConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to get config")
Expand All @@ -40,7 +42,7 @@ func databaseFromTable(table *schemasv1alpha3.Table) (*databasesv1alpha3.Databas
return nil, errors.Wrap(err, "failed to create databases client")
}

database, err := databasesClient.Databases(table.Namespace).Get(table.Spec.Database, metav1.GetOptions{})
database, err := databasesClient.Databases(table.Namespace).Get(ctx, table.Spec.Database, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "failed to get database")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/migration/migration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (r *ReconcileMigration) Reconcile(request reconcile.Request) (reconcile.Res
// so this function is simply an entrypoint that executes the right reconcile loop
instance, instanceErr := r.getInstance(request)
if instanceErr == nil {
result, err := r.reconcileInstance(instance)
result, err := r.reconcileInstance(context.Background(), instance)
if err != nil {
logger.Error(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/migration/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (r *ReconcileMigration) getInstance(request reconcile.Request) (*schemasv1a
return v1alpha3instance, nil
}

func (r *ReconcileMigration) reconcileInstance(instance *schemasv1alpha3.Migration) (reconcile.Result, error) {
func (r *ReconcileMigration) reconcileInstance(ctx context.Context, instance *schemasv1alpha3.Migration) (reconcile.Result, error) {
logger.Debug("reconciling migration",
zap.String("kind", instance.Kind),
zap.String("name", instance.Name),
Expand All @@ -36,11 +36,11 @@ func (r *ReconcileMigration) reconcileInstance(instance *schemasv1alpha3.Migrati
return reconcile.Result{}, errors.Wrap(err, "failed to create config map")
}

table, err := tableFromMigration(instance)
table, err := tableFromMigration(ctx, instance)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get table")
}
database, err := databaseFromTable(table)
database, err := databaseFromTable(ctx, table)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get database")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/table/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

func (r *ReconcileTable) reconcilePod(pod *corev1.Pod) (reconcile.Result, error) {
func (r *ReconcileTable) reconcilePod(ctx context.Context, pod *corev1.Pod) (reconcile.Result, error) {
podLabels := pod.GetObjectMeta().GetLabels()
role, ok := podLabels["schemahero-role"]
if !ok {
Expand Down Expand Up @@ -57,7 +57,7 @@ func (r *ReconcileTable) reconcilePod(pod *corev1.Pod) (reconcile.Result, error)

podLogOpts := corev1.PodLogOptions{}
req := client.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &podLogOpts)
podLogs, err := req.Stream()
podLogs, err := req.Stream(ctx)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to open log stream")
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (r *ReconcileTable) reconcilePod(pod *corev1.Pod) (reconcile.Result, error)
return reconcile.Result{}, errors.Wrap(err, "failed to create schema client")
}

table, err := schemasClient.Tables(tableNamespace).Get(tableName, metav1.GetOptions{})
table, err := schemasClient.Tables(tableNamespace).Get(ctx, tableName, metav1.GetOptions{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get existing table")
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (r *ReconcileTable) reconcilePod(pod *corev1.Pod) (reconcile.Result, error)
return reconcile.Result{}, errors.Wrap(err, "Failed to create database client")
}

database, err := databasesClient.Databases(tableNamespace).Get(table.Spec.Database, metav1.GetOptions{})
database, err := databasesClient.Databases(tableNamespace).Get(ctx, table.Spec.Database, metav1.GetOptions{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get database")
}
Expand Down

0 comments on commit 7c724a6

Please sign in to comment.