Skip to content

Commit acc77ba

Browse files
fix(ci): image publish step by using build repository (#47)
* chore(Taskfile): add `pkg` directory as code directory * chore: remove Dockerfile and .dockerignore * feat: release v0.0.4 * fix: imports * refactor(imports): `openv1alpha1` to `clustersv1alpha1` * fix: linting errors
1 parent 98894c1 commit acc77ba

File tree

14 files changed

+40
-68
lines changed

14 files changed

+40
-68
lines changed

.dockerignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

Dockerfile

Lines changed: 0 additions & 35 deletions
This file was deleted.

Taskfile.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ vars:
44
NESTED_MODULES: api
55
API_DIRS: '{{.ROOT_DIR}}/api/v1alpha1/...'
66
MANIFEST_OUT: '{{.ROOT_DIR}}/api/crds/manifests'
7-
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/v1alpha1/...'
7+
CODE_DIRS: '{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/v1alpha1/... {{.ROOT_DIR}}/pkg/...'
88
COMPONENTS: 'cluster-provider-kind'
99
REPO_NAME: 'https://github.com/openmcp-project/cluster-provider-kind'
1010
GENERATE_DOCS_INDEX: "false"

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.3-dev
1+
v0.0.4

cmd/cluster-provider-kind/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3939
"sigs.k8s.io/controller-runtime/pkg/webhook"
4040

41-
openv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
41+
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
4242

4343
"github.com/openmcp-project/cluster-provider-kind/api/crds"
4444
kindv1alpha1 "github.com/openmcp-project/cluster-provider-kind/api/v1alpha1"
@@ -57,7 +57,7 @@ func init() {
5757
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5858

5959
utilruntime.Must(kindv1alpha1.AddToScheme(scheme))
60-
utilruntime.Must(openv1alpha1.AddToScheme(scheme))
60+
utilruntime.Must(clustersv1alpha1.AddToScheme(scheme))
6161

6262
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
6363
// +kubebuilder:scaffold:scheme

internal/controller/accessrequest_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3131
logf "sigs.k8s.io/controller-runtime/pkg/log"
3232

33-
openv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
33+
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
3434

3535
"github.com/openmcp-project/cluster-provider-kind/pkg/kind"
3636
)
@@ -55,7 +55,7 @@ type AccessRequestReconciler struct {
5555
func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5656
_ = logf.FromContext(ctx)
5757

58-
ar := &openv1alpha1.AccessRequest{}
58+
ar := &clustersv1alpha1.AccessRequest{}
5959
if err := r.Get(ctx, req.NamespacedName, ar); err != nil {
6060
if apierrors.IsNotFound(err) {
6161
return ctrl.Result{}, nil
@@ -64,7 +64,7 @@ func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req ctrl.Reques
6464
}
6565

6666
clusterRef := types.NamespacedName{Name: ar.Spec.ClusterRef.Name, Namespace: ar.Namespace}
67-
cluster := &openv1alpha1.Cluster{}
67+
cluster := &clustersv1alpha1.Cluster{}
6868
if err := r.Get(ctx, clusterRef, cluster); err != nil {
6969
return ctrl.Result{}, errors.Join(err, errFailedToGetReferencedCluster)
7070
}
@@ -99,7 +99,7 @@ func (r *AccessRequestReconciler) Reconcile(ctx context.Context, req ctrl.Reques
9999
// SetupWithManager sets up the controller with the Manager.
100100
func (r *AccessRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
101101
return ctrl.NewControllerManagedBy(mgr).
102-
For(&openv1alpha1.AccessRequest{}).
102+
For(&clustersv1alpha1.AccessRequest{}).
103103
Named("accessrequest").
104104
Complete(r)
105105
}

internal/controller/cluster_controller.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3131
logf "sigs.k8s.io/controller-runtime/pkg/log"
3232

33-
openv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
33+
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
3434
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
3535

3636
"github.com/openmcp-project/cluster-provider-kind/pkg/kind"
@@ -40,7 +40,7 @@ import (
4040

4141
var (
4242
// Finalizer is the finalizer for Cluster
43-
Finalizer = openv1alpha1.GroupVersion.Group + "/finalizer"
43+
Finalizer = clustersv1alpha1.GroupVersion.Group + "/finalizer"
4444
)
4545

4646
// ClusterReconciler reconciles a Cluster object
@@ -62,7 +62,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
6262
log.Info("Reconcile")
6363
defer log.Info("Done")
6464

65-
cluster := &openv1alpha1.Cluster{}
65+
cluster := &clustersv1alpha1.Cluster{}
6666
if err := r.Get(ctx, req.NamespacedName, cluster); err != nil {
6767
if apierrors.IsNotFound(err) {
6868
return ctrl.Result{}, nil
@@ -83,7 +83,7 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
8383
return r.handleCreateOrUpdate(ctx, cluster)
8484
}
8585

86-
func (r *ClusterReconciler) handleDelete(ctx context.Context, cluster *openv1alpha1.Cluster) (ctrl.Result, error) {
86+
func (r *ClusterReconciler) handleDelete(ctx context.Context, cluster *clustersv1alpha1.Cluster) (ctrl.Result, error) {
8787
requeue := smartrequeue.FromContext(ctx)
8888
cluster.Status.Phase = commonapi.StatusPhaseTerminating
8989

@@ -114,7 +114,7 @@ func (r *ClusterReconciler) handleDelete(ctx context.Context, cluster *openv1alp
114114
}
115115

116116
//nolint:gocyclo
117-
func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, cluster *openv1alpha1.Cluster) (ctrl.Result, error) {
117+
func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, cluster *clustersv1alpha1.Cluster) (ctrl.Result, error) {
118118
requeue := smartrequeue.FromContext(ctx)
119119
cluster.Status.Phase = commonapi.StatusPhaseProgressing
120120

@@ -201,12 +201,12 @@ func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, cluster *o
201201
// SetupWithManager sets up the controller with the Manager.
202202
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
203203
return ctrl.NewControllerManagedBy(mgr).
204-
For(&openv1alpha1.Cluster{}).
204+
For(&clustersv1alpha1.Cluster{}).
205205
Named("cluster").
206206
Complete(r)
207207
}
208208

209-
func (r *ClusterReconciler) assignSubnet(ctx context.Context, cluster *openv1alpha1.Cluster) error {
209+
func (r *ClusterReconciler) assignSubnet(ctx context.Context, cluster *clustersv1alpha1.Cluster) error {
210210
_, ok := cluster.Annotations[kind.AnnotationAssignedSubnet]
211211
if ok {
212212
return nil
@@ -221,7 +221,7 @@ func (r *ClusterReconciler) assignSubnet(ctx context.Context, cluster *openv1alp
221221
return r.Update(ctx, cluster)
222222
}
223223

224-
func kindName(cluster *openv1alpha1.Cluster) string {
224+
func kindName(cluster *clustersv1alpha1.Cluster) string {
225225
return fmt.Sprintf("%s.%s", namespaceOrDefault(cluster.Namespace), cluster.Name)
226226
}
227227

pkg/kind/networking.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"sync"
1212

13-
openv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
13+
clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
1414

1515
"sigs.k8s.io/controller-runtime/pkg/client"
1616
)
@@ -27,7 +27,8 @@ var (
2727
errNoSubnetsAvailable = errors.New("no subnets available")
2828
errInvalidIP = errors.New("invalid textual representation of an IP address")
2929

30-
AnnotationAssignedSubnet = openv1alpha1.GroupVersion.Group + "/assigned-subnet"
30+
// AnnotationAssignedSubnet is the annotation used to store the assigned subnet for a cluster
31+
AnnotationAssignedSubnet = clustersv1alpha1.GroupVersion.Group + "/assigned-subnet"
3132
lockListClusters = sync.Mutex{}
3233
)
3334

@@ -46,6 +47,7 @@ func getDockerContainerIP(containerName string) (net.IP, error) {
4647
return parsed, nil
4748
}
4849

50+
// GetDockerV4Network retrieves the IPv4 network configuration of the Docker network named "kind".
4951
func GetDockerV4Network(ctx context.Context) (net.IPNet, error) {
5052
cmd := exec.CommandContext(ctx, "docker", "network", "inspect", "-f", "json", networkName)
5153
cmdOut, err := cmd.Output()
@@ -80,6 +82,7 @@ func isIPv4(ipNet *net.IPNet) bool {
8082
return ipNet.IP.To4() != nil
8183
}
8284

85+
// NextAvailableLBNetwork finds the next available subnet for MetalLB in the Docker network.
8386
func NextAvailableLBNetwork(ctx context.Context, c client.Client) (net.IPNet, error) {
8487
lockListClusters.Lock()
8588
defer lockListClusters.Unlock()
@@ -89,7 +92,7 @@ func NextAvailableLBNetwork(ctx context.Context, c client.Client) (net.IPNet, er
8992
return net.IPNet{}, err
9093
}
9194

92-
clusters := &openv1alpha1.ClusterList{}
95+
clusters := &clustersv1alpha1.ClusterList{}
9396
if err := c.List(ctx, clusters); err != nil {
9497
return net.IPNet{}, err
9598
}
@@ -100,7 +103,7 @@ func NextAvailableLBNetwork(ctx context.Context, c client.Client) (net.IPNet, er
100103
return net.IPNet{}, err
101104
}
102105

103-
taken, err := isIpNetTaken(subnet, clusters)
106+
taken, err := isIPNetTaken(subnet, clusters)
104107
if err != nil {
105108
return net.IPNet{}, err
106109
}
@@ -119,6 +122,7 @@ func calculateV4Subnet(input net.IPNet, offset int) (net.IPNet, error) {
119122
ones, bits := input.Mask.Size()
120123

121124
// Subnet mask should be either 8 or 16 out of 32
125+
// nolint:staticcheck
122126
if !(ones == 8 || ones == 16) || bits != 32 {
123127
return net.IPNet{}, errUnsupportedNetwork
124128
}
@@ -132,7 +136,7 @@ func calculateV4Subnet(input net.IPNet, offset int) (net.IPNet, error) {
132136
}, nil
133137
}
134138

135-
func isIpNetTaken(ipnet net.IPNet, clusters *openv1alpha1.ClusterList) (bool, error) {
139+
func isIPNetTaken(ipnet net.IPNet, clusters *clustersv1alpha1.ClusterList) (bool, error) {
136140
for _, c := range clusters.Items {
137141
cNet, err := SubnetFromCluster(&c)
138142
if err != nil {
@@ -148,7 +152,8 @@ func isIpNetTaken(ipnet net.IPNet, clusters *openv1alpha1.ClusterList) (bool, er
148152
return false, nil
149153
}
150154

151-
func SubnetFromCluster(c *openv1alpha1.Cluster) (*net.IPNet, error) {
155+
// SubnetFromCluster extracts the assigned subnet from the cluster annotations.
156+
func SubnetFromCluster(c *clustersv1alpha1.Cluster) (*net.IPNet, error) {
152157
ipNetStr, ok := c.Annotations[AnnotationAssignedSubnet]
153158
if !ok {
154159
return nil, nil

pkg/kind/networking_model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type ConfigFrom struct {
3030
// Network represents the network configuration struct.
3131
type Network struct {
3232
Name string `json:"Name"`
33-
Id string `json:"Id"`
33+
ID string `json:"ID"`
3434
Created string `json:"Created"`
3535
Scope string `json:"Scope"`
3636
Driver string `json:"Driver"`

pkg/kind/networking_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func Test_parseDockerV4Network(t *testing.T) {
1616
}{
1717
{
1818
desc: "should find v4 network",
19-
jsonData: `[{"Name":"kind","Id":"12da2f79f0833bc2f200a19430f0681ebcb34172f31c4e36be5fc1b98baa0cbc","Created":"2023-05-30T11:29:09.1977428+02:00","Scope":"local","Driver":"bridge","EnableIPv6":true,"IPAM":{"Driver":"default","Options":{},"Config":[{"Subnet":"172.19.0.0/16","Gateway":"172.19.0.1"},{"Subnet":"fc00:f853:ccd:e793::/64","Gateway":"fc00:f853:ccd:e793::1"}]},"Internal":false,"Attachable":false,"Ingress":false,"ConfigFrom":{"Network":""},"ConfigOnly":false,"Containers":{"6f2a311eac05dd159140c280f38b28f4af5fac24966619ae67351a04ac0b0872":{"Name":"kube-system.three-control-plane","EndpointID":"49c7b225fd21d6103458cb44fdbba915eaf078ff87f8721c88bee5048c404e58","MacAddress":"02:42:ac:13:00:04","IPv4Address":"172.19.0.4/16","IPv6Address":"fc00:f853:ccd:e793::4/64"},"9ac1ca74027bed08fd22d325352d1d5fa65478912c98de9c3e322ccaacd5ac2d":{"Name":"default.one-control-plane","EndpointID":"bb99a7571e0d0e6e8ae39c9c2b1e7649f766872035668665e5465d8b3d72aaa7","MacAddress":"02:42:ac:13:00:03","IPv4Address":"172.19.0.3/16","IPv6Address":"fc00:f853:ccd:e793::3/64"},"af9a154989d0ce28dfcf9fc38a9f377fcb9cdd8d0d74ba92260ed2e2bcb43e0e":{"Name":"kind-control-plane","EndpointID":"f70b3da9503ff6abae8a8e51fa7eabf20ca764012bf2a5d20ce1b82a2d928195","MacAddress":"02:42:ac:13:00:05","IPv4Address":"172.19.0.5/16","IPv6Address":"fc00:f853:ccd:e793::5/64"},"fc752ade5c09e3d4f45f2bf498a7ed4c2a06dc451be417ebda109f862317293a":{"Name":"default.two-control-plane","EndpointID":"8fcd5372145cfe0a7705a9e0d8bafa1fa9c5fdaed94528434e6a74a3f09733bd","MacAddress":"02:42:ac:13:00:02","IPv4Address":"172.19.0.2/16","IPv6Address":"fc00:f853:ccd:e793::2/64"}},"Options":{"com.docker.network.bridge.enable_ip_masquerade":"true","com.docker.network.driver.mtu":"1500"},"Labels":{}}]`,
19+
jsonData: `[{"Name":"kind","ID":"12da2f79f0833bc2f200a19430f0681ebcb34172f31c4e36be5fc1b98baa0cbc","Created":"2023-05-30T11:29:09.1977428+02:00","Scope":"local","Driver":"bridge","EnableIPv6":true,"IPAM":{"Driver":"default","Options":{},"Config":[{"Subnet":"172.19.0.0/16","Gateway":"172.19.0.1"},{"Subnet":"fc00:f853:ccd:e793::/64","Gateway":"fc00:f853:ccd:e793::1"}]},"Internal":false,"Attachable":false,"Ingress":false,"ConfigFrom":{"Network":""},"ConfigOnly":false,"Containers":{"6f2a311eac05dd159140c280f38b28f4af5fac24966619ae67351a04ac0b0872":{"Name":"kube-system.three-control-plane","EndpointID":"49c7b225fd21d6103458cb44fdbba915eaf078ff87f8721c88bee5048c404e58","MacAddress":"02:42:ac:13:00:04","IPv4Address":"172.19.0.4/16","IPv6Address":"fc00:f853:ccd:e793::4/64"},"9ac1ca74027bed08fd22d325352d1d5fa65478912c98de9c3e322ccaacd5ac2d":{"Name":"default.one-control-plane","EndpointID":"bb99a7571e0d0e6e8ae39c9c2b1e7649f766872035668665e5465d8b3d72aaa7","MacAddress":"02:42:ac:13:00:03","IPv4Address":"172.19.0.3/16","IPv6Address":"fc00:f853:ccd:e793::3/64"},"af9a154989d0ce28dfcf9fc38a9f377fcb9cdd8d0d74ba92260ed2e2bcb43e0e":{"Name":"kind-control-plane","EndpointID":"f70b3da9503ff6abae8a8e51fa7eabf20ca764012bf2a5d20ce1b82a2d928195","MacAddress":"02:42:ac:13:00:05","IPv4Address":"172.19.0.5/16","IPv6Address":"fc00:f853:ccd:e793::5/64"},"fc752ade5c09e3d4f45f2bf498a7ed4c2a06dc451be417ebda109f862317293a":{"Name":"default.two-control-plane","EndpointID":"8fcd5372145cfe0a7705a9e0d8bafa1fa9c5fdaed94528434e6a74a3f09733bd","MacAddress":"02:42:ac:13:00:02","IPv4Address":"172.19.0.2/16","IPv6Address":"fc00:f853:ccd:e793::2/64"}},"Options":{"com.docker.network.bridge.enable_ip_masquerade":"true","com.docker.network.driver.mtu":"1500"},"Labels":{}}]`,
2020
expectedNet: mustParseCIDR("172.19.0.0/16"),
2121
expectedErr: nil,
2222
},

0 commit comments

Comments
 (0)