Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
  • Loading branch information
NotTheEvilOne committed Dec 21, 2023
1 parent 1bf5835 commit e263d87
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
55 changes: 24 additions & 31 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ limitations under the License.
// Package main is the main package.
package main

// Import packages including all Kubernetes client auth plugins: k8s.io/client-go/plugin/pkg/client/auth

Check failure on line 20 in cmd/main.go

View workflow job for this annotation

GitHub Actions / Lint Pull Request

Comment should end in a period (godot)
import (
"flag"
"os"

infrastructureclusterstackxk8siov1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"github.com/sovereignCloudStack/cluster-stack-provider-openstack/internal/controller"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
runtimeutils "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand All @@ -36,51 +35,46 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
k8sScheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("clusterstack-provider-openstack-setup")
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(infrastructureclusterstackxk8siov1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
runtimeutils.Must(scheme.AddToScheme(k8sScheme))
runtimeutils.Must(apiv1alpha1.AddToScheme(k8sScheme))
}

func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var (
metricsAddr string
enableLeaderElection bool
probeAddr string
)

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(
&enableLeaderElection,
"leader-elect",
false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.",
)

opts := zap.Options{
Development: true,
}

opts.BindFlags(flag.CommandLine)
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Scheme: k8sScheme,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "26a5dd7c.clusterstack.x-k8s.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
LeaderElectionID: "openstack.provider.clusterstack.x-k8s.io",
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -108,7 +102,6 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "OpenStackNodeImageRelease")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controller
import (
"context"

infrav1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -48,7 +48,7 @@ type OpenStackClusterStackReleaseReconciler struct {
func (r *OpenStackClusterStackReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

openstackclusterstackrelease := &infrav1alpha1.OpenStackClusterStackRelease{}
openstackclusterstackrelease := &apiv1alpha1.OpenStackClusterStackRelease{}
_ = r.Client.Get(ctx, req.NamespacedName, openstackclusterstackrelease)

// TODO(user): your logic here
Expand All @@ -59,6 +59,6 @@ func (r *OpenStackClusterStackReleaseReconciler) Reconcile(ctx context.Context,
// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackClusterStackReleaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&infrav1alpha1.OpenStackClusterStackRelease{}).
For(&apiv1alpha1.OpenStackClusterStackRelease{}).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controller
import (
"context"

infrav1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -48,7 +48,7 @@ type OpenStackClusterStackReleaseTemplateReconciler struct {
func (r *OpenStackClusterStackReleaseTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

openstackclusterstackreleasetemplate := &infrav1alpha1.OpenStackClusterStackReleaseTemplate{}
openstackclusterstackreleasetemplate := &apiv1alpha1.OpenStackClusterStackReleaseTemplate{}
_ = r.Client.Get(ctx, req.NamespacedName, openstackclusterstackreleasetemplate)

return ctrl.Result{}, nil
Expand All @@ -57,6 +57,6 @@ func (r *OpenStackClusterStackReleaseTemplateReconciler) Reconcile(ctx context.C
// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackClusterStackReleaseTemplateReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&infrav1alpha1.OpenStackClusterStackReleaseTemplate{}).
For(&apiv1alpha1.OpenStackClusterStackReleaseTemplate{}).
Complete(r)
}
6 changes: 3 additions & 3 deletions internal/controller/openstacknodeimagerelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package controller
import (
"context"

infrav1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -49,7 +49,7 @@ type OpenStackNodeImageReleaseReconciler struct {
func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

openstacknodeimagerelease := infrav1alpha1.OpenStackNodeImageRelease{}
openstacknodeimagerelease := apiv1alpha1.OpenStackNodeImageRelease{}
_ = r.Client.Get(ctx, req.NamespacedName, &openstacknodeimagerelease)

return ctrl.Result{}, nil
Expand All @@ -58,6 +58,6 @@ func (r *OpenStackNodeImageReleaseReconciler) Reconcile(ctx context.Context, req
// SetupWithManager sets up the controller with the Manager.
func (r *OpenStackNodeImageReleaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&infrav1alpha1.OpenStackNodeImageRelease{}).
For(&apiv1alpha1.OpenStackNodeImageRelease{}).
Complete(r)
}
4 changes: 2 additions & 2 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
infrastructureclusterstackxk8siov1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
apiv1alpha1 "github.com/sovereignCloudStack/cluster-stack-provider-openstack/api/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -71,7 +71,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

err = infrastructureclusterstackxk8siov1alpha1.AddToScheme(scheme.Scheme)
err = apiv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme
Expand Down

0 comments on commit e263d87

Please sign in to comment.