Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Sep 20, 2023
2 parents 6052cdf + 3eedbf2 commit c68b20b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 29 deletions.
10 changes: 7 additions & 3 deletions common/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import (
)

func init() {
Logger = NewDefault().Sugar()
DefaultOptions = NewDefaultOptions()
Logger = NewFromOptions(DefaultOptions).Sugar()
}

var Logger *zap.SugaredLogger
var (
Logger *zap.SugaredLogger
DefaultOptions Options
)

// Options exports a options struct to be used by cmd's.
// Options exports options struct to be used by cmd's.
type Options struct {
// Enable debug logs
Debug bool
Expand Down
11 changes: 6 additions & 5 deletions providers/argocd/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"

"github.com/pluralsh/deployment-operator/common/log"
"github.com/pluralsh/deployment-operator/providers/argocd/pkg/provider"
"github.com/pluralsh/deployment-operator/provisioner"
)
Expand All @@ -35,11 +36,11 @@ func init() {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

flag.Set("alsologtostderr", "true")
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
//klog.InitFlags(kflags)
zapFlags := flag.NewFlagSet("zap", flag.ExitOnError)
log.DefaultOptions.AddFlags(zapFlags)

persistentFlags := cmd.PersistentFlags()
persistentFlags.AddGoFlagSet(kflags)
persistentFlags.AddGoFlagSet(zapFlags)

stringFlag := persistentFlags.StringVarP

Expand All @@ -63,9 +64,9 @@ func run(ctx context.Context, args []string) error {
identityServer,
deploymentProvisioner)
if err != nil {
//klog.Errorf("Failed to create provisioner server %v", err)
log.Logger.Errorf("Failed to create provisioner server %v", err)
return err
}
//klog.Info("Starting Elastic provisioner")
log.Logger.Info("Starting Elastic provisioner")
return server.Run(ctx)
}
8 changes: 5 additions & 3 deletions providers/argocd/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os/signal"
"syscall"
"time"

"github.com/pluralsh/deployment-operator/common/log"
)

func main() {
Expand All @@ -16,15 +18,15 @@ func main() {
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

go func() {
_ = <-sigs
//klog.InfoS("Signal received", "type", sig)
sig := <-sigs
log.Logger.Infow("Signal received", "type", sig)
cancel()

<-time.After(30 * time.Second)
os.Exit(1)
}()

if err := cmd.ExecuteContext(ctx); err != nil {
//klog.ErrorS(err, "Exiting on error")
log.Logger.Errorf("exiting on error: %s", err)
}
}
2 changes: 1 addition & 1 deletion providers/argocd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/argoproj/argo-cd/v2 v2.8.4
github.com/pluralsh/deployment-operator/common v0.0.0-00010101000000-000000000000
github.com/pluralsh/deployment-operator/provisioner v0.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -98,7 +99,6 @@ require (
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pluralsh/deployment-operator/common v0.0.0-00010101000000-000000000000 // indirect
github.com/r3labs/diff v1.1.0 // indirect
github.com/redis/go-redis/v9 v9.0.5 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
Expand Down
6 changes: 6 additions & 0 deletions providers/argocd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand All @@ -907,6 +908,7 @@ golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1021,6 +1023,7 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1153,6 +1156,7 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -1164,6 +1168,7 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1181,6 +1186,7 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
10 changes: 5 additions & 5 deletions providers/fake/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"flag"
"strings"

"github.com/pluralsh/deployment-operator/fake/pkg/provider"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/klog/v2"

"github.com/pluralsh/deployment-operator/common/log"
"github.com/pluralsh/deployment-operator/fake/pkg/provider"
"github.com/pluralsh/deployment-operator/provisioner"
)

Expand All @@ -36,11 +36,11 @@ func init() {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))

flag.Set("alsologtostderr", "true")
kflags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(kflags)
zapFlags := flag.NewFlagSet("zap", flag.ExitOnError)
log.DefaultOptions.AddFlags(zapFlags)

persistentFlags := cmd.PersistentFlags()
persistentFlags.AddGoFlagSet(kflags)
persistentFlags.AddGoFlagSet(zapFlags)

stringFlag := persistentFlags.StringVarP

Expand Down
6 changes: 3 additions & 3 deletions providers/fake/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"syscall"
"time"

"k8s.io/klog/v2"
"github.com/pluralsh/deployment-operator/common/log"
)

func main() {
Expand All @@ -19,14 +19,14 @@ func main() {

go func() {
sig := <-sigs
klog.InfoS("Signal received", "type", sig)
log.Logger.Infow("Signal received", "type", sig)
cancel()

<-time.After(30 * time.Second)
os.Exit(1)
}()

if err := cmd.ExecuteContext(ctx); err != nil {
klog.ErrorS(err, "Exiting on error")
log.Logger.Errorf("exiting on error: %s", err)
}
}
6 changes: 3 additions & 3 deletions providers/fake/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/pluralsh/deployment-operator/fake
go 1.21

require (
github.com/pluralsh/deployment-operator/common v0.0.0-00010101000000-000000000000
github.com/pluralsh/deployment-operator/provisioner v0.0.0-00010101000000-000000000000
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
google.golang.org/grpc v1.58.1
k8s.io/apimachinery v0.28.2
k8s.io/klog/v2 v2.100.1
)

require (
Expand All @@ -28,7 +28,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pluralsh/deployment-operator/common v0.0.0-00010101000000-000000000000 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -44,6 +43,7 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/controller-runtime v0.16.2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand All @@ -54,4 +54,4 @@ require (
replace (
github.com/pluralsh/deployment-operator/common => ./../../common
github.com/pluralsh/deployment-operator/provisioner => ./../../provisioner
)
)
11 changes: 5 additions & 6 deletions providers/fake/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package provider

import (
"context"
"errors"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/util/rand"

"github.com/pluralsh/deployment-operator/common/log"
deploymentspec "github.com/pluralsh/deployment-operator/provisioner/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
)

func NewProvider(provider string) (*IdentityServer, *Server) {
Expand Down Expand Up @@ -41,7 +40,7 @@ func (ps *Server) ProviderGetDeploymentStatus(ctx context.Context, request *depl

func (ps *Server) ProviderCreateDeployment(_ context.Context, req *deploymentspec.ProviderCreateDeploymentRequest) (*deploymentspec.ProviderCreateDeploymentResponse, error) {
deploymentName := req.GetName()
klog.V(3).InfoS("Create Deployment", "name", deploymentName)
log.Logger.Infow("Create Deployment", "name", deploymentName)

if ps.deployment[deploymentName] != "" {
return &deploymentspec.ProviderCreateDeploymentResponse{}, status.Error(codes.AlreadyExists, "Deployment already exists")
Expand Down Expand Up @@ -70,7 +69,7 @@ type IdentityServer struct {

func (id *IdentityServer) ProviderGetInfo(context.Context, *deploymentspec.ProviderGetInfoRequest) (*deploymentspec.ProviderGetInfoResponse, error) {
if id.provider == "" {
klog.ErrorS(errors.New("provider name cannot be empty"), "Invalid argument")
log.Logger.Error("provider name cannot be empty", "Invalid argument")
return nil, status.Error(codes.InvalidArgument, "ProviderName is empty")
}

Expand Down

0 comments on commit c68b20b

Please sign in to comment.