Skip to content

Commit 2035ec9

Browse files
authored
Merge pull request Skarlso#104 from Skarlso/add-remote-cluster
feat: add remote cluster apply
2 parents b81b77d + c5d6c35 commit 2035ec9

16 files changed

+207
-135
lines changed

.golangci.yaml

+39-56
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,52 @@ run:
88
linters:
99
enable-all: true
1010
disable:
11-
# We are working on it
12-
- wrapcheck
11+
- bodyclose
12+
- containedctx # Struct should not contain context, action does.
13+
- contextcheck
14+
- cyclop # Complex functions are not good.
15+
- deadcode
1316
- depguard
14-
# Logical next step
15-
- forcetypeassert # Priority: that can lead to serious crashes.
17+
- dogsled
18+
- dupl # Check code duplications.
19+
- execinquery
20+
- exhaustive # Doesn't really make sense.
21+
- exhaustivestruct
22+
- exhaustruct # Doesn't really make sense.
1623
- exportloopref
17-
- goerr113 # Do not define dynamic errors with Errorf.
18-
- varnamelen # m, d, p < These are not so meaningful variables.
19-
- testpackage # Blackbox testing is preffered.
24+
- forcetypeassert # Priority: that can lead to serious crashes.
2025
- funlen # Break long functions.
26+
- gci
27+
- gochecknoglobals
28+
- gochecknoinits # Init functions cause an import to have side effects,
29+
- goerr113
30+
- goimports # acts weirdly, dci handles imports anyway
31+
- golint
2132
- gomnd # Give constant values a name with constants.
33+
- ifshort
34+
- interfacebloat
35+
- interfacer
2236
- ireturn # Accept interface, return concrate.
37+
- lll
38+
- loggercheck # Doesn't really make sense.
39+
- maligned
2340
- nestif # Some nexted if statements are 8 or 9 deep.
24-
- dupl # Check code duplications.
25-
- cyclop # Complex functions are not good.
26-
- gochecknoinits # Init functions cause an import to have side effects,
27-
# and side effects are hard to test,
28-
# reduce readability and increase the complexity of code.
29-
- containedctx # Struct should not contain context, action does.
3041
- nilnil # A function should return either something valuable
31-
# or an error, but both value and error as nil is
32-
# useless. Like when I call it, why is it nil? Tell me
33-
# in an error why.
34-
- bodyclose
35-
- unparam
3642
- nonamedreturns # Either named return, or use simply `return`.
37-
38-
# Opinionated (we may want to keep it disabled)
39-
- gochecknoglobals
40-
- lll
43+
- nosnakecase
4144
- paralleltest
42-
- tagliatelle
43-
- wsl
44-
- interfacebloat
45-
46-
47-
# Disabled with reason
48-
- dogsled
49-
- exhaustruct # Doesn't really make sense.
50-
- exhaustive # Doesn't really make sense.
51-
- logrlint # Doesn't really make sense.
52-
- goimports # acts weirdly, dci handles imports anyway
53-
54-
# Disabled because of generics in go 1.18
55-
- contextcheck
5645
- rowserrcheck
57-
- sqlclosecheck
58-
- wastedassign
59-
60-
# Deprecated
61-
- deadcode
62-
- exhaustivestruct
63-
- golint
64-
- ifshort
65-
- interfacer
66-
- maligned
6746
- scopelint
47+
- sqlclosecheck
6848
- structcheck
49+
- tagliatelle
50+
- testpackage # Blackbox testing is preffered.
51+
- unparam
6952
- varcheck
70-
- gci
53+
- varnamelen # m, d, p < These are not so meaningful variables.
54+
- wastedassign
55+
- wrapcheck
56+
- wsl
7157

7258
linters-settings:
7359
gci:
@@ -76,17 +62,18 @@ linters-settings:
7662
- blank
7763
- dot
7864
- default
65+
- prefix(github.com/open-component-model/ocm)
7966
custom-order: true
80-
staticcheck:
81-
go: "1.22"
82-
stylecheck:
83-
go: "1.22"
8467
funlen:
8568
lines: 110
8669
statements: 60
8770
cyclop:
88-
max-complexity: 20
71+
max-complexity: 46
8972
skip-tests: true
73+
gocognit:
74+
# Minimal code complexity to report.
75+
# Default: 30 (but we recommend 10-20)
76+
min-complexity: 46
9077
nolintlint:
9178
allow-unused: false
9279
require-explanation: true
@@ -108,9 +95,6 @@ issues:
10895
- path: cmds/
10996
linters:
11097
- forbidigo
111-
- text: "should not use dot imports|don't use an underscore in package name"
112-
linters:
113-
- golint
11498
- source: "https://"
11599
linters:
116100
- lll
@@ -122,7 +106,6 @@ issues:
122106
- govet
123107
- path: _test\.go
124108
linters:
125-
- goerr113
126109
- gocyclo
127110
- errcheck
128111
- gosec

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
151151
## Tool Versions
152152
KUSTOMIZE_VERSION ?= v5.0.0
153153
CONTROLLER_TOOLS_VERSION ?= v0.14.0
154-
GOLANGCI_LINT_VERSION ?= v1.55.2
154+
GOLANGCI_LINT_VERSION ?= v1.57.2
155155

156156
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
157157
.PHONY: kustomize

api/v1alpha1/bootstrap_types.go

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1alpha1
1919
import (
2020
"time"
2121

22+
"github.com/fluxcd/pkg/apis/meta"
2223
v1 "k8s.io/api/core/v1"
2324
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -28,6 +29,16 @@ const (
2829
BootstrapOwnerLabelKey = "delivery.crd-bootstrap.owned"
2930
)
3031

32+
// KubeConfig defines as way to access a remote cluster.
33+
type KubeConfig struct {
34+
// ServiceAccount defines any custom service accounts to use in order to
35+
// apply crds in a remote cluster.
36+
ServiceAccount string `json:"serviceAccount,omitempty"`
37+
// SecretRef defines a secret with the key in which the kubeconfig is in.
38+
// +optional
39+
SecretRef *meta.KubeConfigReference `json:"secretRef,omitempty"`
40+
}
41+
3142
// GitHub defines a GitHub type source where the CRD is coming from `release` section of a GitHub repository.
3243
type GitHub struct {
3344
// BaseURL is used for the GitHub url. Defaults to github.com if not defined.
@@ -169,6 +180,10 @@ type BootstrapSpec struct {
169180
// Prune will clean up all applied objects once the Bootstrap object is removed.
170181
// +optional
171182
Prune bool `json:"prune,omitempty"`
183+
184+
// KubeConfig defines a kubeconfig that could be used to access another cluster and apply a CRD there.
185+
// +optional
186+
KubeConfig *KubeConfig `json:"kubeConfig,omitempty"`
172187
}
173188

174189
// BootstrapStatus defines the observed state of Bootstrap.

api/v1alpha1/zz_generated.deepcopy.go

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ func main() {
5858
var metricsAddr string
5959
var enableLeaderElection bool
6060
var probeAddr string
61+
var defaultServiceAccount string
6162
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6263
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6364
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6465
"Enable leader election for controller manager. "+
6566
"Enabling this will ensure there is only one active controller manager.")
67+
flag.StringVar(&defaultServiceAccount, "default-service-account", "", "Default service account used for impersonation.")
6668
opts := zap.Options{
6769
Development: true,
6870
}
@@ -95,9 +97,10 @@ func main() {
9597
configMapProvider := configmap.NewSource(mgr.GetClient(), gitlabProvider)
9698
helmProvider := helm.NewSource(c, mgr.GetClient(), configMapProvider)
9799
if err = (&controller.BootstrapReconciler{
98-
Client: mgr.GetClient(),
99-
Scheme: mgr.GetScheme(),
100-
SourceProvider: helmProvider,
100+
Client: mgr.GetClient(),
101+
Scheme: mgr.GetScheme(),
102+
SourceProvider: helmProvider,
103+
DefaultServiceAccount: defaultServiceAccount,
101104
}).SetupWithManager(mgr); err != nil {
102105
setupLog.Error(err, "unable to create controller", "controller", "Bootstrap")
103106
os.Exit(1)

crd-bootstrap/crds/delivery.crd-bootstrap_bootstraps.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@ spec:
4747
description: Interval defines the regular interval at which a poll
4848
for new version should happen.
4949
type: string
50+
kubeConfig:
51+
description: KubeConfig defines a kubeconfig that could be used to
52+
access another cluster and apply a CRD there.
53+
properties:
54+
secretRef:
55+
description: SecretRef defines a secret with the key in which
56+
the kubeconfig is in.
57+
properties:
58+
secretRef:
59+
description: |-
60+
SecretRef holds the name of a secret that contains a key with
61+
the kubeconfig file as the value. If no key is set, the key will default
62+
to 'value'.
63+
It is recommended that the kubeconfig is self-contained, and the secret
64+
is regularly updated if credentials such as a cloud-access-token expire.
65+
Cloud specific `cmd-path` auth helpers will not function without adding
66+
binaries and credentials to the Pod that is responsible for reconciling
67+
Kubernetes resources.
68+
properties:
69+
key:
70+
description: Key in the Secret, when not specified an
71+
implementation-specific default key is used.
72+
type: string
73+
name:
74+
description: Name of the Secret.
75+
type: string
76+
required:
77+
- name
78+
type: object
79+
required:
80+
- secretRef
81+
type: object
82+
serviceAccount:
83+
description: |-
84+
ServiceAccount defines any custom service accounts to use in order to
85+
apply crds in a remote cluster.
86+
type: string
87+
type: object
5088
prune:
5189
description: Prune will clean up all applied objects once the Bootstrap
5290
object is removed.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require (
1818
k8s.io/api v0.30.3
1919
k8s.io/apiextensions-apiserver v0.30.3
2020
k8s.io/apimachinery v0.30.3
21-
k8s.io/cli-runtime v0.30.3
2221
k8s.io/client-go v0.30.3
2322
oras.land/oras-go v1.2.6
2423
sigs.k8s.io/controller-runtime v0.18.4
@@ -135,6 +134,7 @@ require (
135134
gopkg.in/yaml.v2 v2.4.0 // indirect
136135
gopkg.in/yaml.v3 v3.0.1 // indirect
137136
k8s.io/apiserver v0.30.3 // indirect
137+
k8s.io/cli-runtime v0.30.3 // indirect
138138
k8s.io/component-base v0.30.3 // indirect
139139
k8s.io/klog/v2 v2.120.1 // indirect
140140
k8s.io/kube-openapi v0.0.0-20240411171206-dc4e619f62f3 // indirect

0 commit comments

Comments
 (0)