Skip to content

Commit

Permalink
Add common Github actions (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbenjemaa authored Aug 17, 2023
1 parent 07d1f18 commit 427372b
Show file tree
Hide file tree
Showing 31 changed files with 1,590 additions and 79 deletions.
4 changes: 4 additions & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
capi
proxmox
capmox
decorder
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
15 changes: 15 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Helps catch spelling errors
name: Codespell
on: [ pull_request ]

jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # v2.5.0
- uses: codespell-project/actions-codespell@22ff5a2e4b591290baf82d47c9feadac31c65441 # v1.0
with:
skip: .git,_artifacts,*.sum
ignore_words_file: .codespellignore
check_filenames: true
check_hidden: true
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Lint
on: [ pull_request ]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.54
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Test
on: [ pull_request ]

jobs:
go_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
- run: "make test"
131 changes: 131 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- misspell
- nakedret
- nilerr
- nolintlint
- prealloc
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

linters-settings:
ifshort:
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
max-decl-chars: 50
importas:
no-unaliased: true
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
alias: clusterv1
staticcheck:
go: "1.19"
stylecheck:
go: "1.19"

issues:
max-same-issues: 0
max-issues-per-linter: 0
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
# changes in PRs and avoid nitpicking.
exclude-use-default: false
# List of regexps of issue texts to exclude, empty list by default.
exclude:
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
# If it is decided they will not be addressed they should be moved above this comment.
- Subprocess launch(ed with variable|ing should be audited)
- (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)
- (G104|G307)
exclude-rules:
- linters:
- gosec
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
- linters:
- revive
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
- linters:
- errcheck
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# With Go 1.16, the new embed directive can be used with an un-named import,
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
# This directive allows the embed package to be imported with an underscore everywhere.
- linters:
- revive
source: _ "embed"
# Exclude some packages or code to require comments, for example test code, or fake clients.
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
source: (func|type).*Fake.*
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: fake_\.go
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: "(framework|e2e|infrastructure/docker)/.*.go"
# Disable unparam "always receives" which might not be really
# useful when building libraries.
- linters:
- unparam
text: always receives
# Dot imports for gomega or ginkgo are allowed
# within test files.
- path: _test\.go
text: should not use dot imports
- path: (framework|e2e)/.*.go
text: should not use dot imports
- path: _test\.go
text: cyclomatic complexity
# Append should be able to assign to a different var/slice.
- linters:
- gocritic
text: "appendAssign: append result not assigned to the same slice"


run:
timeout: 10m
skip-files:
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
skip-dirs:
- mock*
allow-parallel-runners: true
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: lint
lint: ## Run lint.
go run -modfile ./hack/tools/go.mod github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 5m -c .golangci.yml

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
// VMProvisionFailedReason used for failures during instance provisioning.
VMProvisionFailedReason = "VMProvisionFailed"

// VMTerminatedReason used when vm is being terminated.
VMTerminatedReason = "VMTerminated"

// WaitingForClusterInfrastructureReason (Severity=Info) documents a ProxmoxMachine waiting for the cluster
Expand Down Expand Up @@ -65,8 +66,8 @@ const (
// NotFoundReason (Severity=Warning) documents the ProxmoxVM not found.
NotFoundReason = "NotFound"

// UnkownReason (Severity=Warning) documents the ProxmoxVM Unkown.
UnkownReason = "Unkown"
// UnknownReason (Severity=Warning) documents the ProxmoxVM Unknown.
UnknownReason = "Unknown"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
)

var (
// GroupVersion is group version used to register these objects
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
Expand Down
11 changes: 7 additions & 4 deletions api/v1alpha1/proxmoxcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
)

const (
// ProxmoxClusterKind the ProxmoxCluster kind.
ProxmoxClusterKind = "ProxmoxCluster"
// ClusterFinalizer allows cleaning up resources associated with
// ProxmoxCluster before removing it from the apiserver.
ClusterFinalizer = "proxmoxcluster.infrastructure.cluster.x-k8s.io"
)

// ProxmoxClusterSpec defines the desired state of ProxmoxCluster
// ProxmoxClusterSpec defines the desired state of ProxmoxCluster.
type ProxmoxClusterSpec struct {
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
Expand All @@ -38,7 +39,7 @@ type ProxmoxClusterSpec struct {
Node *string `json:"node,omitempty"`
}

// ProxmoxClusterStatus defines the observed state of ProxmoxCluster
// ProxmoxClusterStatus defines the observed state of ProxmoxCluster.
type ProxmoxClusterStatus struct {
// Ready indicates that the cluster is ready.
// +optional
Expand All @@ -57,7 +58,7 @@ type ProxmoxClusterStatus struct {
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready"
//+kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.controlPlaneEndpoint",description="API Endpoint"

// ProxmoxCluster is the Schema for the proxmoxclusters API
// ProxmoxCluster is the Schema for the proxmoxclusters API.
type ProxmoxCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -68,17 +69,19 @@ type ProxmoxCluster struct {

//+kubebuilder:object:root=true

// ProxmoxClusterList contains a list of ProxmoxCluster
// ProxmoxClusterList contains a list of ProxmoxCluster.
type ProxmoxClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProxmoxCluster `json:"items"`
}

// GetConditions returns the observations of the operational state of the ProxmoxCluster resource.
func (c *ProxmoxCluster) GetConditions() clusterv1.Conditions {
return c.Status.Conditions
}

// SetConditions sets the underlying service state of the ProxmoxCluster to the predescribed clusterv1.Conditions.
func (c *ProxmoxCluster) SetConditions(conditions clusterv1.Conditions) {
c.Status.Conditions = conditions
}
Expand Down
17 changes: 10 additions & 7 deletions api/v1alpha1/proxmoxmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

const (
// ProxmoxMachineKind the ProxmoxMachine kind.
ProxmoxMachineKind = "ProxmoxMachine"

// MachineFinalizer allows cleaning up resources associated with
Expand All @@ -35,21 +36,23 @@ const (
DefaultReconcilerRequeue = 10 * time.Second
)

// ProxmoxMachineSpec defines the desired state of ProxmoxMachine
// ProxmoxMachineSpec defines the desired state of ProxmoxMachine.
type ProxmoxMachineSpec struct {
VirtualMachineCloneSpec `json:",inline"`

// ProviderID is the virtual machine's BIOS UUID formated as
// proxmox://12345678-1234-1234-1234-123456789abc
// ProviderID is the virtual machine's VM ID formatted as
// proxmox://node/100
// +optional
ProviderID *string `json:"providerID,omitempty"`

// VirtualMachineID is the Proxmox identifier for the ProxmoxMachine instance.
VirtualMachineID *int64 `json:"virtualMachineID,omitempty"`
}

// TargetFileStorageFormat the target format of the cloned disk.
type TargetFileStorageFormat string

// Supported disk formats.
const (
TargetStorageFormatRaw TargetFileStorageFormat = "raw"
TargetStorageFormatQcow2 TargetFileStorageFormat = "qcow2"
Expand Down Expand Up @@ -99,7 +102,7 @@ type VirtualMachineCloneSpec struct {
Target *string `json:"target,omitempty"`
}

// ProxmoxMachineStatus defines the observed state of ProxmoxMachine
// ProxmoxMachineStatus defines the observed state of ProxmoxMachine.
type ProxmoxMachineStatus struct {
// Ready indicates the docker infrastructure has been provisioned and is ready
// +optional
Expand Down Expand Up @@ -184,7 +187,7 @@ type ProxmoxMachineStatus struct {
// +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".spec.providerID",description="VM ID"
// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this ProxmoxMachine"

// ProxmoxMachine is the Schema for the proxmoxmachines API
// ProxmoxMachine is the Schema for the proxmoxmachines API.
type ProxmoxMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -195,7 +198,7 @@ type ProxmoxMachine struct {

//+kubebuilder:object:root=true

// ProxmoxMachineList contains a list of ProxmoxMachine
// ProxmoxMachineList contains a list of ProxmoxMachine.
type ProxmoxMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand All @@ -212,7 +215,7 @@ func (r *ProxmoxMachine) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

// GetNode get the proxmox node used to provision this machine
// GetNode get the proxmox node used to provision this machine.
func (r *ProxmoxMachine) GetNode() string {
return r.Spec.Node
}
Expand Down
Loading

0 comments on commit 427372b

Please sign in to comment.