Skip to content

Commit 9511c01

Browse files
authored
Merge pull request #188 from k8s-proxmox/feature/update-pkgs
Feature/update pkgs
2 parents c9c9e66 + 543f8ed commit 9511c01

File tree

8 files changed

+472
-826
lines changed

8 files changed

+472
-826
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
name: lint
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v3
16-
- uses: actions/setup-go@v4
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v5
1717
with:
18-
go-version: 1.20.5
18+
go-version: 1.22.10
1919
check-latest: true
2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v3.4.0
21+
uses: golangci/golangci-lint-action@v6.2.0
2222
with:
23-
version: v1.53.3
23+
version: v1.54.0
2424
args: --timeout 5m

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
run:
2+
skip-dirs:
3+
- sigs.k8s.io/cluster-api

cloud/scope/machine.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ import (
2424
"github.com/pkg/errors"
2525
corev1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/types"
27-
"k8s.io/utils/pointer"
27+
"k8s.io/utils/ptr"
2828
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
29-
"sigs.k8s.io/cluster-api/controllers/noderefutil"
3029
capierrors "sigs.k8s.io/cluster-api/errors"
3130
"sigs.k8s.io/cluster-api/util/patch"
3231
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -165,11 +164,11 @@ func (m *MachineScope) SetInstanceStatus(v infrav1.InstanceStatus) {
165164
}
166165

167166
func (m *MachineScope) GetBiosUUID() *string {
168-
parsed, err := noderefutil.NewProviderID(m.GetProviderID()) //nolint: staticcheck
167+
parsed, err := NewProviderID(m.GetProviderID()) //nolint: staticcheck
169168
if err != nil {
170169
return nil
171170
}
172-
return pointer.String(parsed.ID()) //nolint: staticcheck
171+
return ptr.To(parsed.ID()) //nolint: staticcheck
173172
}
174173

175174
func (m *MachineScope) GetProviderID() string {
@@ -209,7 +208,7 @@ func (m *MachineScope) SetProviderID(uuid string) error {
209208
if err != nil {
210209
return err
211210
}
212-
m.ProxmoxMachine.Spec.ProviderID = pointer.String(providerid.String())
211+
m.ProxmoxMachine.Spec.ProviderID = ptr.To(providerid.String())
213212
return nil
214213
}
215214

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

228227
func (m *MachineScope) SetFailureMessage(v error) {
229-
m.ProxmoxMachine.Status.FailureMessage = pointer.String(v.Error())
228+
m.ProxmoxMachine.Status.FailureMessage = ptr.To(v.Error())
230229
}
231230

232231
func (m *MachineScope) SetFailureReason(v capierrors.MachineStatusError) {

cloud/scope/providerid.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package scope
18+
19+
import (
20+
"errors"
21+
"net/url"
22+
"path"
23+
)
24+
25+
var (
26+
ErrEmptyProviderID = errors.New("providerID is empty")
27+
ErrInvalidProviderID = errors.New("providerID is not valid")
28+
)
29+
30+
// ProviderID is a struct representation of a Kubernetes ProviderID.
31+
// Format: cloudProvider://optional/segments/etc/id
32+
type ProviderID struct {
33+
value *url.URL
34+
}
35+
36+
// NewProviderID parses the input string and returns a new ProviderID.
37+
func NewProviderID(id string) (*ProviderID, error) {
38+
if id == "" {
39+
return nil, ErrEmptyProviderID
40+
}
41+
42+
parsed, err := url.Parse(id)
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
res := &ProviderID{
48+
value: parsed,
49+
}
50+
51+
if !res.Validate() {
52+
return nil, ErrInvalidProviderID
53+
}
54+
55+
return res, nil
56+
}
57+
58+
// CloudProvider returns the cloud provider portion of the ProviderID.
59+
func (p *ProviderID) CloudProvider() string {
60+
return p.value.Scheme
61+
}
62+
63+
// ID returns the identifier portion of the ProviderID.
64+
func (p *ProviderID) ID() string {
65+
return path.Base(p.value.Path)
66+
}
67+
68+
// Equals returns true if both the CloudProvider and ID match.
69+
func (p *ProviderID) Equals(o *ProviderID) bool {
70+
return p.CloudProvider() == o.CloudProvider() && p.ID() == o.ID()
71+
}
72+
73+
// String returns the string representation of this object.
74+
func (p *ProviderID) String() string {
75+
return p.value.String()
76+
}
77+
78+
// Validate returns true if the provider id is valid.
79+
func (p *ProviderID) Validate() bool {
80+
return p.CloudProvider() != "" &&
81+
p.ID() != "" &&
82+
p.ID() != "/" // path.Base returns "/" if consists only of slashes.
83+
}

cloud/services/compute/instance/reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/k8s-proxmox/proxmox-go/proxmox"
99
"github.com/k8s-proxmox/proxmox-go/rest"
1010
"github.com/pkg/errors"
11-
"k8s.io/utils/pointer"
11+
"k8s.io/utils/ptr"
1212
"sigs.k8s.io/controller-runtime/pkg/log"
1313

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

138138
// reconciles qemu, cloud-config, os image and storage

cmd/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,32 @@ import (
2323
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2424
// to ensure that exec-entrypoint and run can make use of them.
2525
_ "k8s.io/client-go/plugin/pkg/client/auth"
26-
"k8s.io/klog/v2"
2726

27+
"github.com/spf13/pflag"
2828
"k8s.io/apimachinery/pkg/runtime"
2929
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3030
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3131
cliflag "k8s.io/component-base/cli/flag"
3232
"k8s.io/component-base/logs"
3333
logsv1 "k8s.io/component-base/logs/api/v1"
34+
"k8s.io/klog/v2"
3435
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
36+
"sigs.k8s.io/cluster-api/util/flags"
3537
ctrl "sigs.k8s.io/controller-runtime"
3638
"sigs.k8s.io/controller-runtime/pkg/healthz"
3739

3840
infrastructurev1beta1 "github.com/k8s-proxmox/cluster-api-provider-proxmox/api/v1beta1"
3941
"github.com/k8s-proxmox/cluster-api-provider-proxmox/cloud/scheduler"
4042
controller "github.com/k8s-proxmox/cluster-api-provider-proxmox/controllers"
41-
"github.com/spf13/pflag"
4243
//+kubebuilder:scaffold:imports
4344
)
4445

4546
var (
46-
scheme = runtime.NewScheme()
47-
setupLog = ctrl.Log.WithName("setup")
47+
scheme = runtime.NewScheme()
48+
setupLog = ctrl.Log.WithName("setup")
49+
managerOptions = flags.ManagerOptions{}
4850

4951
// flags
50-
metricsAddr string
5152
enableLeaderElection bool
5253
probeAddr string
5354
pluginConfig string
@@ -74,12 +75,16 @@ func main() {
7475
// }
7576
pflag.Parse()
7677

78+
_, metricsOptions, err := flags.GetManagerOptions(managerOptions)
79+
if err != nil {
80+
setupLog.Error(err, "Unable to start manager: invalid flags")
81+
}
82+
7783
ctrl.SetLogger(klog.Background())
7884

7985
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
8086
Scheme: scheme,
81-
MetricsBindAddress: metricsAddr,
82-
Port: 9443,
87+
Metrics: *metricsOptions,
8388
HealthProbeBindAddress: probeAddr,
8489
LeaderElection: enableLeaderElection,
8590
LeaderElectionID: "36404136.cluster.x-k8s.io",
@@ -146,10 +151,11 @@ func main() {
146151
func InitFlags(fs *pflag.FlagSet) {
147152
logsv1.AddFlags(logOptions, fs)
148153

149-
fs.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
150154
fs.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
151155
fs.BoolVar(&enableLeaderElection, "leader-elect", false,
152156
"Enable leader election for controller manager. "+
153157
"Enabling this will ensure there is only one active controller manager.")
154158
fs.StringVar(&pluginConfig, "scheduler-plugin-config", "", "The config file path for qemu-scheduler plugins")
159+
160+
flags.AddManagerOptions(fs, &managerOptions)
155161
}

0 commit comments

Comments
 (0)