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

Feature/update pkgs #188

Merged
merged 5 commits into from
Feb 1, 2025
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
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.20.5
go-version: 1.22.10
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.4.0
uses: golangci/golangci-lint-action@v6.2.0
with:
version: v1.53.3
version: v1.54.0
args: --timeout 5m
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
run:
skip-dirs:
- sigs.k8s.io/cluster-api
11 changes: 5 additions & 6 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -165,11 +164,11 @@ func (m *MachineScope) SetInstanceStatus(v infrav1.InstanceStatus) {
}

func (m *MachineScope) GetBiosUUID() *string {
parsed, err := noderefutil.NewProviderID(m.GetProviderID()) //nolint: staticcheck
parsed, err := NewProviderID(m.GetProviderID()) //nolint: staticcheck
if err != nil {
return nil
}
return pointer.String(parsed.ID()) //nolint: staticcheck
return ptr.To(parsed.ID()) //nolint: staticcheck
}

func (m *MachineScope) GetProviderID() string {
Expand Down Expand Up @@ -209,7 +208,7 @@ func (m *MachineScope) SetProviderID(uuid string) error {
if err != nil {
return err
}
m.ProxmoxMachine.Spec.ProviderID = pointer.String(providerid.String())
m.ProxmoxMachine.Spec.ProviderID = ptr.To(providerid.String())
return nil
}

Expand All @@ -226,7 +225,7 @@ func (m *MachineScope) SetReady() {
}

func (m *MachineScope) SetFailureMessage(v error) {
m.ProxmoxMachine.Status.FailureMessage = pointer.String(v.Error())
m.ProxmoxMachine.Status.FailureMessage = ptr.To(v.Error())
}

func (m *MachineScope) SetFailureReason(v capierrors.MachineStatusError) {
Expand Down
83 changes: 83 additions & 0 deletions cloud/scope/providerid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2019 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package scope

import (
"errors"
"net/url"
"path"
)

var (
ErrEmptyProviderID = errors.New("providerID is empty")
ErrInvalidProviderID = errors.New("providerID is not valid")
)

// ProviderID is a struct representation of a Kubernetes ProviderID.
// Format: cloudProvider://optional/segments/etc/id
type ProviderID struct {
value *url.URL
}

// NewProviderID parses the input string and returns a new ProviderID.
func NewProviderID(id string) (*ProviderID, error) {
if id == "" {
return nil, ErrEmptyProviderID
}

parsed, err := url.Parse(id)
if err != nil {
return nil, err
}

res := &ProviderID{
value: parsed,
}

if !res.Validate() {
return nil, ErrInvalidProviderID
}

return res, nil
}

// CloudProvider returns the cloud provider portion of the ProviderID.
func (p *ProviderID) CloudProvider() string {
return p.value.Scheme
}

// ID returns the identifier portion of the ProviderID.
func (p *ProviderID) ID() string {
return path.Base(p.value.Path)
}

// Equals returns true if both the CloudProvider and ID match.
func (p *ProviderID) Equals(o *ProviderID) bool {
return p.CloudProvider() == o.CloudProvider() && p.ID() == o.ID()
}

// String returns the string representation of this object.
func (p *ProviderID) String() string {
return p.value.String()
}

// Validate returns true if the provider id is valid.
func (p *ProviderID) Validate() bool {
return p.CloudProvider() != "" &&
p.ID() != "" &&
p.ID() != "/" // path.Base returns "/" if consists only of slashes.
}
4 changes: 2 additions & 2 deletions cloud/services/compute/instance/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/k8s-proxmox/proxmox-go/proxmox"
"github.com/k8s-proxmox/proxmox-go/rest"
"github.com/pkg/errors"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/log"

infrav1 "github.com/k8s-proxmox/cluster-api-provider-proxmox/api/v1beta1"
Expand Down Expand Up @@ -132,7 +132,7 @@ func getBiosUUIDFromVM(ctx context.Context, vm *proxmox.VirtualMachine) (*string
log.Error(err, "failed to convert SMBios to UUID")
return nil, err
}
return pointer.String(uuid), nil
return ptr.To(uuid), nil
}

// reconciles qemu, cloud-config, os image and storage
Expand Down
22 changes: 14 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,32 @@ import (
// 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/klog/v2"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
logsv1 "k8s.io/component-base/logs/api/v1"
"k8s.io/klog/v2"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/flags"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"

infrastructurev1beta1 "github.com/k8s-proxmox/cluster-api-provider-proxmox/api/v1beta1"
"github.com/k8s-proxmox/cluster-api-provider-proxmox/cloud/scheduler"
controller "github.com/k8s-proxmox/cluster-api-provider-proxmox/controllers"
"github.com/spf13/pflag"
//+kubebuilder:scaffold:imports
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
managerOptions = flags.ManagerOptions{}

// flags
metricsAddr string
enableLeaderElection bool
probeAddr string
pluginConfig string
Expand All @@ -74,12 +75,16 @@ func main() {
// }
pflag.Parse()

_, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to start manager: invalid flags")
}

ctrl.SetLogger(klog.Background())

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Metrics: *metricsOptions,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "36404136.cluster.x-k8s.io",
Expand Down Expand Up @@ -146,10 +151,11 @@ func main() {
func InitFlags(fs *pflag.FlagSet) {
logsv1.AddFlags(logOptions, fs)

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(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
fs.StringVar(&pluginConfig, "scheduler-plugin-config", "", "The config file path for qemu-scheduler plugins")

flags.AddManagerOptions(fs, &managerOptions)
}
Loading