Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 603f196

Browse files
committed
refactoring, adding sample deployment to this repo
1 parent 7f43ac3 commit 603f196

File tree

780 files changed

+62043
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

780 files changed

+62043
-91
lines changed

api/v1alpha1/cdk8sappproxy_webook.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package v1alpha1
33
import (
44
"fmt"
55

6-
runtime "k8s.io/apimachinery/pkg/runtime"
6+
"k8s.io/apimachinery/pkg/runtime"
77
ctrl "sigs.k8s.io/controller-runtime"
88
logf "sigs.k8s.io/controller-runtime/pkg/log"
99
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -13,9 +13,9 @@ import (
1313
// log is for logging in this package.
1414
var cdk8sappproxylog = logf.Log.WithName("cdk8sappproxy-resource")
1515

16-
func (r *Cdk8sAppProxy) SetupWebhookWithManager(mgr ctrl.Manager) error {
16+
func (c *Cdk8sAppProxy) SetupWebhookWithManager(mgr ctrl.Manager) error {
1717
return ctrl.NewWebhookManagedBy(mgr).
18-
For(r).
18+
For(c).
1919
Complete()
2020
}
2121

@@ -25,17 +25,17 @@ func (r *Cdk8sAppProxy) SetupWebhookWithManager(mgr ctrl.Manager) error {
2525
var _ webhook.Defaulter = &Cdk8sAppProxy{}
2626

2727
// Default implements webhook.CustomDefaulter so a webhook will be registered for the type.
28-
func (r *Cdk8sAppProxy) Default() {
29-
cdk8sappproxylog.Info("default", "name", r.Name)
28+
func (c *Cdk8sAppProxy) Default() {
29+
cdk8sappproxylog.Info("default", "name", c.Name)
3030

31-
// Set default git reference if not specified
32-
if r.Spec.GitRepository != nil && r.Spec.GitRepository.Reference == "" {
33-
r.Spec.GitRepository.Reference = "main"
31+
// Set the default git reference if not specified
32+
if c.Spec.GitRepository != nil && c.Spec.GitRepository.Reference == "" {
33+
c.Spec.GitRepository.Reference = "main"
3434
}
3535

36-
// Set default path if not specified
37-
if r.Spec.GitRepository != nil && r.Spec.GitRepository.Path == "" {
38-
r.Spec.GitRepository.Path = "."
36+
// Set the default path if not specified
37+
if c.Spec.GitRepository != nil && c.Spec.GitRepository.Path == "" {
38+
c.Spec.GitRepository.Path = "."
3939
}
4040
}
4141

@@ -44,42 +44,42 @@ func (r *Cdk8sAppProxy) Default() {
4444
var _ webhook.Validator = &Cdk8sAppProxy{}
4545

4646
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type.
47-
func (r *Cdk8sAppProxy) ValidateCreate() (admission.Warnings, error) {
48-
cdk8sappproxylog.Info("validate create", "name", r.Name)
47+
func (c *Cdk8sAppProxy) ValidateCreate() (admission.Warnings, error) {
48+
cdk8sappproxylog.Info("validate create", "name", c.Name)
4949

50-
return r.validateCdk8sAppProxy()
50+
return c.validateCdk8sAppProxy()
5151
}
5252

53-
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type.
54-
func (r *Cdk8sAppProxy) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
55-
cdk8sappproxylog.Info("validate update", "name", r.Name)
53+
// ValidateUpdate implement webhook.CustomValidator so a webhook will be registered for the type.
54+
func (c *Cdk8sAppProxy) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
55+
cdk8sappproxylog.Info("validate update", "name", c.Name)
5656

57-
return r.validateCdk8sAppProxy()
57+
return c.validateCdk8sAppProxy()
5858
}
5959

6060
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type.
61-
func (r *Cdk8sAppProxy) ValidateDelete() (admission.Warnings, error) {
62-
cdk8sappproxylog.Info("validate delete", "name", r.Name)
61+
func (c *Cdk8sAppProxy) ValidateDelete() (admission.Warnings, error) {
62+
cdk8sappproxylog.Info("validate delete", "name", c.Name)
6363

6464
// No validation needed for delete
6565
return nil, nil
6666
}
6767

68-
func (r *Cdk8sAppProxy) validateCdk8sAppProxy() (admission.Warnings, error) {
68+
func (c *Cdk8sAppProxy) validateCdk8sAppProxy() (admission.Warnings, error) {
6969
var allErrs []error
7070

7171
// Validate that either LocalPath or GitRepository is specified, but not both
72-
if r.Spec.LocalPath != "" && r.Spec.GitRepository != nil {
72+
if c.Spec.LocalPath != "" && c.Spec.GitRepository != nil {
7373
allErrs = append(allErrs, fmt.Errorf("only one of localPath or gitRepository can be specified"))
7474
}
7575

76-
if r.Spec.LocalPath == "" && r.Spec.GitRepository == nil {
76+
if c.Spec.LocalPath == "" && c.Spec.GitRepository == nil {
7777
allErrs = append(allErrs, fmt.Errorf("either localPath or gitRepository must be specified"))
7878
}
7979

8080
// Validate GitRepository fields if specified
81-
if r.Spec.GitRepository != nil {
82-
if r.Spec.GitRepository.URL == "" {
81+
if c.Spec.GitRepository != nil {
82+
if c.Spec.GitRepository.URL == "" {
8383
allErrs = append(allErrs, fmt.Errorf("gitRepository.url is required when gitRepository is specified"))
8484
}
8585
}

api/v1alpha1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
)
2626

2727
var (
28-
// GroupVersion is group version used to register these objects.
28+
// GroupVersion is a group version used to register these objects.
2929
GroupVersion = schema.GroupVersion{Group: "addons.cluster.x-k8s.io", Version: "v1alpha1"}
3030

3131
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/cdk8sappproxy/cdk8sappproxy_controller.go

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -95,48 +95,6 @@ func (r *Reconciler) getCdk8sAppProxyForPolling(ctx context.Context, proxyName t
9595
return cdk8sAppProxy, nil
9696
}
9797

98-
func (r *Reconciler) updateRemoteGitHashStatus(ctx context.Context, proxyName types.NamespacedName, remoteCommitHash string, logger logr.Logger) error {
99-
latestCdk8sAppProxy := &addonsv1alpha1.Cdk8sAppProxy{}
100-
if err := r.Get(ctx, proxyName, latestCdk8sAppProxy); err != nil {
101-
logger.Error(err, "Failed to get latest Cdk8sAppProxy before status update")
102-
103-
return err
104-
}
105-
106-
latestCdk8sAppProxy.Status.LastRemoteGitHash = remoteCommitHash
107-
if err := r.Status().Update(ctx, latestCdk8sAppProxy); err != nil {
108-
logger.Error(err, "Failed to update Cdk8sAppProxy status with new remote hash")
109-
110-
return err
111-
}
112-
113-
logger.Info("Successfully updated status with new remote hash. Now triggering reconciliation.")
114-
115-
return nil
116-
}
117-
118-
// Write implements the io.Writer interface.
119-
func (gpl *gitProgressLogger) Write(p []byte) (n int, err error) {
120-
gpl.buffer = append(gpl.buffer, p...)
121-
for {
122-
idx := bytes.IndexByte(gpl.buffer, '\n')
123-
if idx == -1 {
124-
// If buffer gets too large without a newline, log it to prevent OOM
125-
if len(gpl.buffer) > 1024 {
126-
gpl.logger.Info(strings.TrimSpace(string(gpl.buffer)))
127-
gpl.buffer = nil
128-
}
129-
130-
break
131-
}
132-
line := gpl.buffer[:idx]
133-
gpl.buffer = gpl.buffer[idx+1:]
134-
gpl.logger.Info(strings.TrimSpace(string(line)))
135-
}
136-
137-
return len(p), nil
138-
}
139-
14098
// checkIfResourceExists checks if a given resource exists on the target cluster. It uses a dynamic client to make the check.
14199
func checkIfResourceExists(ctx context.Context, dynClient dynamic.Interface, gvr schema.GroupVersionResource, namespace string, name string) (bool, error) {
142100
resourceGetter := dynClient.Resource(gvr)
@@ -492,7 +450,7 @@ func getPluralFromKind(kind string) string {
492450

493451
// SetupWithManager sets up the controller with the Manager.
494452
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
495-
// Initialize watch system before setting up the controller
453+
// Initialize a watch system before setting up the controller
496454
r.initializeWatchSystem()
497455

498456
return ctrl.NewControllerManagedBy(mgr).

controllers/cdk8sappproxy/cdk8sappproxy_git_operator.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cdk8sappproxy
22

33
import (
4+
"bytes"
45
"context"
56
"os"
67
"path/filepath"
@@ -369,3 +370,44 @@ func (r *Reconciler) stopGitPoller(proxyNamespacedName types.NamespacedName, log
369370
logger.Info("No active git poller found to stop.")
370371
}
371372
}
373+
374+
func (r *Reconciler) updateRemoteGitHashStatus(ctx context.Context, proxyName types.NamespacedName, remoteCommitHash string, logger logr.Logger) error {
375+
latestCdk8sAppProxy := &addonsv1alpha1.Cdk8sAppProxy{}
376+
if err := r.Get(ctx, proxyName, latestCdk8sAppProxy); err != nil {
377+
logger.Error(err, "Failed to get latest Cdk8sAppProxy before status update")
378+
379+
return err
380+
}
381+
382+
latestCdk8sAppProxy.Status.LastRemoteGitHash = remoteCommitHash
383+
if err := r.Status().Update(ctx, latestCdk8sAppProxy); err != nil {
384+
logger.Error(err, "Failed to update Cdk8sAppProxy status with new remote hash")
385+
386+
return err
387+
}
388+
389+
logger.Info("Successfully updated status with new remote hash. Now triggering reconciliation.")
390+
391+
return nil
392+
}
393+
394+
func (gpl *gitProgressLogger) Write(p []byte) (n int, err error) {
395+
gpl.buffer = append(gpl.buffer, p...)
396+
for {
397+
idx := bytes.IndexByte(gpl.buffer, '\n')
398+
if idx == -1 {
399+
// If buffer gets too large without a newline, log it to prevent OOM
400+
if len(gpl.buffer) > 1024 {
401+
gpl.logger.Info(strings.TrimSpace(string(gpl.buffer)))
402+
gpl.buffer = nil
403+
}
404+
405+
break
406+
}
407+
line := gpl.buffer[:idx]
408+
gpl.buffer = gpl.buffer[idx+1:]
409+
gpl.logger.Info(strings.TrimSpace(string(line)))
410+
}
411+
412+
return len(p), nil
413+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: go
2+
app: go run .
3+
imports:
4+
- k8s
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module example.com/cdk8s-test
2+
3+
go 1.24.4
4+
5+
require (
6+
github.com/aws/constructs-go/constructs/v10 v10.3.0
7+
github.com/aws/jsii-runtime-go v1.98.0
8+
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.68.70
9+
)
10+
11+
require (
12+
github.com/Masterminds/semver/v3 v3.3.1 // indirect
13+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
14+
github.com/fatih/color v1.18.0 // indirect
15+
github.com/google/go-cmp v0.7.0 // indirect
16+
github.com/mattn/go-colorable v0.1.13 // indirect
17+
github.com/mattn/go-isatty v0.0.20 // indirect
18+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
19+
github.com/stretchr/testify v1.10.0 // indirect
20+
github.com/yuin/goldmark v1.4.13 // indirect
21+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
22+
golang.org/x/mod v0.24.0 // indirect
23+
golang.org/x/sync v0.14.0 // indirect
24+
golang.org/x/sys v0.33.0 // indirect
25+
golang.org/x/tools v0.33.0 // indirect
26+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
2+
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
3+
github.com/aws/constructs-go/constructs/v10 v10.3.0 h1:LsjBIMiaDX/vqrXWhzTquBJ9pPdi02/H+z1DCwg0PEM=
4+
github.com/aws/constructs-go/constructs/v10 v10.3.0/go.mod h1:GgzwIwoRJ2UYsr3SU+JhAl+gq5j39bEMYf8ev3J+s9s=
5+
github.com/aws/jsii-runtime-go v1.98.0 h1:ulW8WgW9xchCkGc8SBKSQwpm+4/MwoFkYuCsOD8NnMU=
6+
github.com/aws/jsii-runtime-go v1.98.0/go.mod h1:30XYoqvHizeedL8KNra3DBZ9w+NtJDQpbU4o1bN9lVc=
7+
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.68.70 h1:0sS7tHQraB3OtVpS6IElkwwb0XJcCIapo6brFs3IGoQ=
8+
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.68.70/go.mod h1:Pkx19GlJctsR6wchtjV81yKCwdj4K/i+5dRKt6i4HTw=
9+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
10+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
12+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
13+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
14+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
15+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
16+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
17+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
18+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
19+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
20+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
21+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
22+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
23+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
24+
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
25+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
26+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
27+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
28+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
29+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
30+
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
31+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
32+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
33+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
34+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
35+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
36+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
37+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
38+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
39+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
40+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
43+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
44+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
45+
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
46+
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
47+
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
48+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
49+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
========================================================================================================
2+
3+
Your cdk8s Go project is ready!
4+
5+
cat help Prints this message
6+
cdk8s synth Synthesize k8s manifests to dist/
7+
cdk8s import Imports k8s API objects to "imports/k8s"
8+
9+
Deploy:
10+
kubectl apply -f dist/
11+
12+
========================================================================================================
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package k8s
2+
3+
4+
// Affinity is a group of affinity scheduling rules.
5+
type Affinity struct {
6+
// Describes node affinity scheduling rules for the pod.
7+
NodeAffinity *NodeAffinity `field:"optional" json:"nodeAffinity" yaml:"nodeAffinity"`
8+
// Describes pod affinity scheduling rules (e.g. co-locate this pod in the same node, zone, etc. as some other pod(s)).
9+
PodAffinity *PodAffinity `field:"optional" json:"podAffinity" yaml:"podAffinity"`
10+
// Describes pod anti-affinity scheduling rules (e.g. avoid putting this pod in the same node, zone, etc. as some other pod(s)).
11+
PodAntiAffinity *PodAntiAffinity `field:"optional" json:"podAntiAffinity" yaml:"podAntiAffinity"`
12+
}
13+

0 commit comments

Comments
 (0)