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

Fix command line flags #408

Merged
merged 2 commits into from
Sep 10, 2024
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
19 changes: 11 additions & 8 deletions cmd/yawol-cloud-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ import (
"time"

"github.com/spf13/pflag"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/cache"

"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand Down Expand Up @@ -92,6 +90,11 @@ func main() {

fs := pflag.NewFlagSet("yawol-cloud-controller", pflag.ExitOnError)

// register --kubeconfig flag in FlagSet
configFlagSet := flag.NewFlagSet("config", flag.ContinueOnError)
config.RegisterFlags(configFlagSet)
fs.AddGoFlagSet(configFlagSet)

fs.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
fs.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
fs.BoolVar(&controlEnableLeaderElection, "leader-elect", false,
Expand Down
22 changes: 12 additions & 10 deletions cmd/yawol-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,26 @@ import (
"os"
"time"

"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancer"
"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancermachine"
"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancerset"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/spf13/pflag"
"go.uber.org/zap/zapcore"
"golang.org/x/time/rate"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancer"
"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancermachine"
"github.com/stackitcloud/yawol/controllers/yawol-controller/loadbalancerset"
helpermetrics "github.com/stackitcloud/yawol/internal/metrics"
//+kubebuilder:scaffold:imports
)
Expand Down Expand Up @@ -83,6 +80,11 @@ func main() {

fs := pflag.NewFlagSet("yawol-controller", pflag.ExitOnError)

// register --kubeconfig flag in FlagSet
configFlagSet := flag.NewFlagSet("config", flag.ContinueOnError)
config.RegisterFlags(configFlagSet)
fs.AddGoFlagSet(configFlagSet)

fs.StringVar(&metricsAddrLb, "metrics-addr-lb", ":8080", "The address the metric endpoint binds to.")
fs.StringVar(&metricsAddrLbs, "metrics-addr-lbm", ":8081", "The address the metric endpoint binds to.")
fs.StringVar(&metricsAddrLbm, "metrics-addr-lbs", ":8082", "The address the metric endpoint binds to.")
Expand Down
41 changes: 20 additions & 21 deletions cmd/yawollet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,32 @@ import (
"os"
"time"

discoverygrpcv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
"github.com/envoyproxy/go-control-plane/pkg/cache/types"
cachev3 "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
"github.com/envoyproxy/go-control-plane/pkg/resource/v3"
serverv3 "github.com/envoyproxy/go-control-plane/pkg/server/v3"
testv3 "github.com/envoyproxy/go-control-plane/pkg/test/v3"
"github.com/spf13/pflag"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.

_ "k8s.io/client-go/plugin/pkg/client/auth"

yawolv1beta1 "github.com/stackitcloud/yawol/api/v1beta1"
controllers "github.com/stackitcloud/yawol/controllers/yawollet"
yawolhealthz "github.com/stackitcloud/yawol/internal/healthz"
"github.com/stackitcloud/yawol/internal/helper"

"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/envoyproxy/go-control-plane/pkg/cache/types"
cachev3 "github.com/envoyproxy/go-control-plane/pkg/cache/v3"
serverv3 "github.com/envoyproxy/go-control-plane/pkg/server/v3"
testv3 "github.com/envoyproxy/go-control-plane/pkg/test/v3"
"google.golang.org/grpc"

discoverygrpcv3 "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -71,6 +65,11 @@ func main() {

fs := pflag.NewFlagSet("yawollet", pflag.ExitOnError)

// register --kubeconfig flag in FlagSet
configFlagSet := flag.NewFlagSet("config", flag.ContinueOnError)
config.RegisterFlags(configFlagSet)
fs.AddGoFlagSet(configFlagSet)

fs.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. Default is disabled.")
fs.StringVar(&probeAddr, "health-probe-bind-address", "127.0.0.1:8080", "The address the probe endpoint binds to.")

Expand Down
14 changes: 7 additions & 7 deletions internal/helper/loadbalancermachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ func GenerateUserData(
}

var yawolletArgs string
yawolletArgs = yawolletArgs + "-namespace=" + loadbalancerMachine.Namespace + " "
yawolletArgs = yawolletArgs + "-loadbalancer-name=" + loadbalancer.Name + " "
yawolletArgs = yawolletArgs + "-loadbalancer-machine-name=" + loadbalancerMachine.Name + " "
yawolletArgs = yawolletArgs + "-listen-address=" + vip + " "
yawolletArgs = yawolletArgs + "-health-probe-bind-address=" + probeAddress + " "
yawolletArgs = yawolletArgs + "-kubeconfig /etc/yawol/kubeconfig" + " "
yawolletArgs = yawolletArgs + "--namespace=" + loadbalancerMachine.Namespace + " "
yawolletArgs = yawolletArgs + "--loadbalancer-name=" + loadbalancer.Name + " "
yawolletArgs = yawolletArgs + "--loadbalancer-machine-name=" + loadbalancerMachine.Name + " "
yawolletArgs = yawolletArgs + "--listen-address=" + vip + " "
yawolletArgs = yawolletArgs + "--health-probe-bind-address=" + probeAddress + " "
yawolletArgs = yawolletArgs + "--kubeconfig /etc/yawol/kubeconfig" + " "

if yawolletRequeueTime > 0 {
yawolletArgs = yawolletArgs + "-requeue-time=" + strconv.Itoa(yawolletRequeueTime) + " "
yawolletArgs = yawolletArgs + "--requeue-time=" + strconv.Itoa(yawolletRequeueTime) + " "
}

return `
Expand Down