Skip to content

Commit

Permalink
fix: revert golint setup as it introduce bug on netlink add
Browse files Browse the repository at this point in the history
* revert back to 2.4.0

* cherry pick 2.6.1

* cherry pick 2.6.0
  • Loading branch information
winston0410 authored Jul 18, 2024
1 parent af353df commit c779a46
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 216 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/golangci-lint.yml

This file was deleted.

21 changes: 0 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
## [2.6.1](https://github.com/jodevsa/wireguard-operator/compare/v2.6.0...v2.6.1) (2024-07-17)


### Bug Fixes

* only add address as loadbalancerIP if svc type is LoadBalancer ([#203](https://github.com/jodevsa/wireguard-operator/issues/203)) ([56a609d](https://github.com/jodevsa/wireguard-operator/commit/56a609df561dd4d47509a6d6f406e4785a715890))

# [2.6.0](https://github.com/jodevsa/wireguard-operator/compare/v2.5.0...v2.6.0) (2024-07-17)


### Features

* support ClusterIP service ([#201](https://github.com/jodevsa/wireguard-operator/issues/201)) ([a82d2bb](https://github.com/jodevsa/wireguard-operator/commit/a82d2bbeb26e5297d935d83556ba18f596878af8))

# [2.5.0](https://github.com/jodevsa/wireguard-operator/compare/v2.4.0...v2.5.0) (2024-07-15)


### Features

* add golint support ([71150ea](https://github.com/jodevsa/wireguard-operator/commit/71150ea483dbf9f605d75fff86bc4dd91de92414))

# [2.4.0](https://github.com/jodevsa/wireguard-operator/compare/v2.3.2...v2.4.0) (2024-07-15)


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ Endpoint = 32.121.45.102:51820

## How to deploy
```
kubectl apply -f https://github.com/jodevsa/wireguard-operator/releases/download/v2.5.0/release.yaml
kubectl apply -f https://github.com/jodevsa/wireguard-operator/releases/download/v2.1.0/release.yaml
```

## How to remove
```
kubectl delete -f https://github.com/jodevsa/wireguard-operator/releases/download/v2.5.0/release.yaml
kubectl delete -f https://github.com/jodevsa/wireguard-operator/releases/download/v2.1.0/release.yaml
```

## How to collaborate
Expand Down
8 changes: 4 additions & 4 deletions internal/it/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func waitForDeploymentTobeReady(name string, namespace string) {
}

deployment := &v12.Deployment{}
Expect(k8sClient.Get(context.Background(), deploymentKey, deployment)).Should(Succeed())
k8sClient.Get(context.Background(), deploymentKey, deployment)
return int(deployment.Status.ReadyReplicas)
}, Timeout, Interval).Should(Equal(1))

Expand All @@ -73,7 +73,7 @@ func WaitForWireguardToBeReady(name string, namespace string) {
Name: name,
}
wg := &v1alpha1.Wireguard{}
Expect(k8sClient.Get(context.Background(), wgKey, wg)).Should(Succeed())
k8sClient.Get(context.Background(), wgKey, wg)
return wg.Status.Status
}, Timeout, Interval).Should(Equal(v1alpha1.Ready))

Expand All @@ -86,7 +86,7 @@ func WaitForPeerToBeReady(name string, namespace string) {
Name: name,
}
wg := &v1alpha1.WireguardPeer{}
Expect(k8sClient.Get(context.Background(), wgKey, wg)).Should(Succeed())
k8sClient.Get(context.Background(), wgKey, wg)
return wg.Status.Status
}, Timeout, Interval).Should(Equal(v1alpha1.Ready))

Expand Down Expand Up @@ -228,7 +228,7 @@ var _ = BeforeSuite(func() {
}

deployment := &v12.Deployment{}
Expect(k8sClient.Get(context.Background(), deploymentKey, deployment)).Should(Succeed())
k8sClient.Get(context.Background(), deploymentKey, deployment)
return int(deployment.Status.ReadyReplicas)
}, Timeout, Interval).Should(Equal(1))

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/go-logr/logr"
"os"
"path/filepath"

"github.com/fsnotify/fsnotify"
"github.com/go-logr/logr"
"github.com/jodevsa/wireguard-operator/pkg/api/v1alpha1"
)

Expand Down
144 changes: 36 additions & 108 deletions pkg/controllers/wireguard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ func labelsForWireguard(name string) map[string]string {
return map[string]string{"app": "wireguard", "instance": name}
}

func (r *WireguardReconciler) ConfigmapForWireguard(m *v1alpha1.Wireguard, hostname string) (*corev1.ConfigMap, error) {
func (r *WireguardReconciler) ConfigmapForWireguard(m *v1alpha1.Wireguard, hostname string) *corev1.ConfigMap {
ls := labelsForWireguard(m.Name)
dep := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-config",
Namespace: m.Namespace,
Labels: labelsForWireguard(m.Name),
Labels: ls,
},
}
if err := ctrl.SetControllerReference(m, dep, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}
return dep, nil

ctrl.SetControllerReference(m, dep, r.Scheme)
return dep
}

func (r *WireguardReconciler) getWireguardPeers(ctx context.Context, req ctrl.Request) (*v1alpha1.WireguardPeerList, error) {
Expand Down Expand Up @@ -311,11 +311,7 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
err = r.Get(ctx, types.NamespacedName{Name: wireguard.Name + "-metrics-svc", Namespace: wireguard.Namespace}, svcFound)
if err != nil && errors.IsNotFound(err) {

svc, err := r.serviceForWireguardMetrics(wireguard)
if err != nil {
return ctrl.Result{}, fmt.Errorf("service for wireguard metrics: %w", err)
}

svc := r.serviceForWireguardMetrics(wireguard)
log.Info("Creating a new service", "service.Namespace", svc.Namespace, "service.Name", svc.Name)
err = r.Create(ctx, svc)
if err != nil {
Expand Down Expand Up @@ -361,11 +357,7 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

err = r.Get(ctx, types.NamespacedName{Name: wireguard.Name + "-svc", Namespace: wireguard.Namespace}, svcFound)
if err != nil && errors.IsNotFound(err) {
svc, err := r.serviceForWireguard(wireguard, serviceType)
if err != nil {
return ctrl.Result{}, fmt.Errorf("service for wireguard: %w", err)
}

svc := r.serviceForWireguard(wireguard, serviceType)
log.Info("Creating a new service", "service.Namespace", svc.Namespace, "service.Name", svc.Name)
err = r.Create(ctx, svc)
if err != nil {
Expand Down Expand Up @@ -487,15 +479,10 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

if !bytes.Equal(b, secret.Data["state.json"]) {
log.Info("Updating secret with new config")

publicKey := string(secret.Data["publicKey"])

secret, err := r.secretForWireguard(wireguard, b, privateKey, publicKey)
err := r.Update(ctx, r.secretForWireguard(wireguard, b, privateKey, publicKey))
if err != nil {
return ctrl.Result{}, fmt.Errorf("secret for wireguard: %w", err)
}

if err := r.Update(ctx, secret); err != nil {
log.Error(err, "Failed to update secret with new config")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -547,39 +534,14 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
return ctrl.Result{}, err
}

bytes.Equal(b, secret.Data["state"])

secret, err := r.secretForWireguard(wireguard, b, privateKey, publicKey)
if err != nil {
return ctrl.Result{}, fmt.Errorf("secret for wireguard: %w", err)
}
secret := r.secretForWireguard(wireguard, b, privateKey, publicKey)

log.Info("Creating a new secret", "secret.Namespace", secret.Namespace, "secret.Name", secret.Name)

if err := r.Create(ctx, secret); err != nil {
log.Error(err, "Failed to create new secret", "secret.Namespace", secret.Namespace, "secret.Name", secret.Name)
return ctrl.Result{}, err
}

clientKey, err := wgtypes.GeneratePrivateKey()

if err != nil {
log.Error(err, "Failed to generate private key")
return ctrl.Result{}, err
}

clientSecret, err := r.secretForClient(wireguard, clientKey.String(), clientKey.PublicKey().String())
if err != nil {
return ctrl.Result{}, fmt.Errorf("secret for client: %w", err)
}

log.Info("Creating a new secret", "secret.Namespace", clientSecret.Namespace, "secret.Name", clientSecret.Name)
err = r.Create(ctx, clientSecret)
if err != nil {
log.Error(err, "Failed to create new secret", "secret.Namespace", clientSecret.Namespace, "secret.Name", clientSecret.Name)
return ctrl.Result{}, err
}

return ctrl.Result{}, err
} else if err != nil {
log.Error(err, "Failed to get secret")
Expand All @@ -591,14 +553,10 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
configFound := &corev1.ConfigMap{}
err = r.Get(ctx, types.NamespacedName{Name: wireguard.Name + "-config", Namespace: wireguard.Namespace}, configFound)
if err != nil && errors.IsNotFound(err) {
config, err := r.ConfigmapForWireguard(wireguard, address)
if err != nil {
return ctrl.Result{}, fmt.Errorf("config map for wireguard: %w", err)
}

config := r.ConfigmapForWireguard(wireguard, address)
log.Info("Creating a new config", "config.Namespace", config.Namespace, "config.Name", config.Name)

if err := r.Create(ctx, config); err != nil {
err = r.Create(ctx, config)
if err != nil {
log.Error(err, "Failed to create new dep", "dep.Namespace", config.Namespace, "dep.Name", config.Name)
return ctrl.Result{}, err
}
Expand All @@ -616,11 +574,7 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
deploymentFound := &appsv1.Deployment{}
err = r.Get(ctx, types.NamespacedName{Name: wireguard.Name + "-dep", Namespace: wireguard.Namespace}, deploymentFound)
if err != nil && errors.IsNotFound(err) {
dep, err := r.deploymentForWireguard(wireguard)
if err != nil {
return ctrl.Result{}, fmt.Errorf("deployment for wireguard: %w", err)
}

dep := r.deploymentForWireguard(wireguard)
log.Info("Creating a new dep", "dep.Namespace", dep.Namespace, "dep.Name", dep.Name)
err = r.Create(ctx, dep)
if err != nil {
Expand All @@ -635,12 +589,9 @@ func (r *WireguardReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

if deploymentFound.Spec.Template.Spec.Containers[0].Image != r.AgentImage {
dep, err := r.deploymentForWireguard(wireguard)
dep := r.deploymentForWireguard(wireguard)
err = r.Update(ctx, dep)
if err != nil {
return ctrl.Result{}, fmt.Errorf("deployment for wireguard: %w", err)
}

if err := r.Update(ctx, dep); err != nil {
log.Error(err, "unable to update deployment image", "dep.Namespace", dep.Namespace, "dep.Name", dep.Name)
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -673,10 +624,10 @@ func (r *WireguardReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *WireguardReconciler) serviceForWireguard(m *v1alpha1.Wireguard, serviceType corev1.ServiceType) (*corev1.Service, error) {
func (r *WireguardReconciler) serviceForWireguard(m *v1alpha1.Wireguard, serviceType corev1.ServiceType) *corev1.Service {
labels := labelsForWireguard(m.Name)

svc := &corev1.Service{
dep := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-svc",
Namespace: m.Namespace,
Expand All @@ -695,20 +646,18 @@ func (r *WireguardReconciler) serviceForWireguard(m *v1alpha1.Wireguard, service
},
}

if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
svc.Spec.LoadBalancerIP = m.Spec.Address
if dep.Spec.Type == corev1.ServiceTypeLoadBalancer {
dep.Spec.LoadBalancerIP = m.Spec.Address
}

if err := ctrl.SetControllerReference(m, svc, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}
return svc, nil
ctrl.SetControllerReference(m, dep, r.Scheme)
return dep
}

func (r *WireguardReconciler) serviceForWireguardMetrics(m *v1alpha1.Wireguard) (*corev1.Service, error) {
func (r *WireguardReconciler) serviceForWireguardMetrics(m *v1alpha1.Wireguard) *corev1.Service {
labels := labelsForWireguard(m.Name)

svc := &corev1.Service{
dep := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-metrics-svc",
Namespace: m.Namespace,
Expand All @@ -726,48 +675,29 @@ func (r *WireguardReconciler) serviceForWireguardMetrics(m *v1alpha1.Wireguard)
},
}

if err := ctrl.SetControllerReference(m, svc, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}
return svc, nil
ctrl.SetControllerReference(m, dep, r.Scheme)
return dep
}

func (r *WireguardReconciler) secretForWireguard(m *v1alpha1.Wireguard, state []byte, privateKey string, publicKey string) (*corev1.Secret, error) {
secret := &corev1.Secret{
func (r *WireguardReconciler) secretForWireguard(m *v1alpha1.Wireguard, state []byte, privateKey string, publicKey string) *corev1.Secret {

ls := labelsForWireguard(m.Name)
dep := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name,
Namespace: m.Namespace,
Labels: labelsForWireguard(m.Name),
Labels: ls,
},
Data: map[string][]byte{"state.json": state, "privateKey": []byte(privateKey), "publicKey": []byte(publicKey)},
}

if err := ctrl.SetControllerReference(m, secret, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}

return secret, nil

}

func (r *WireguardReconciler) secretForClient(m *v1alpha1.Wireguard, privateKey string, publicKey string) (*corev1.Secret, error) {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name + "-client",
Namespace: m.Namespace,
Labels: labelsForWireguard(m.Name),
},
Data: map[string][]byte{"privateKey": []byte(privateKey), "publicKey": []byte(publicKey)},
}
ctrl.SetControllerReference(m, dep, r.Scheme)

if err := ctrl.SetControllerReference(m, secret, r.Scheme); err != nil {
return nil, fmt.Errorf("set controller reference: %w", err)
}
return secret, nil
return dep

}

func (r *WireguardReconciler) deploymentForWireguard(m *v1alpha1.Wireguard) (*appsv1.Deployment, error) {
func (r *WireguardReconciler) deploymentForWireguard(m *v1alpha1.Wireguard) *appsv1.Deployment {
ls := labelsForWireguard(m.Name)
replicas := int32(1)

Expand Down Expand Up @@ -910,8 +840,6 @@ func (r *WireguardReconciler) deploymentForWireguard(m *v1alpha1.Wireguard) (*ap
}
}

if err := ctrl.SetControllerReference(m, dep, r.Scheme); err != nil {
return dep, fmt.Errorf("set controller reference: %w", err)
}
return dep, nil
ctrl.SetControllerReference(m, dep, r.Scheme)
return dep
}
Loading

0 comments on commit c779a46

Please sign in to comment.