Skip to content

Commit

Permalink
Merge pull request #5 from damsien/main
Browse files Browse the repository at this point in the history
🌱 Use global syngit functions
  • Loading branch information
damsien authored Dec 26, 2024
2 parents 274c2e5 + 9dd271a commit f686739
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Image URL to use all building/pushing image targets
IMG ?= local/syngit-provider-github-controller:dev
IMG ?= local/syngit-provider-github:dev
DEV_CLUSTER ?= syngit-dev-cluster
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.0
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

syngitv1beta2 "github.com/syngit-org/syngit/api/v1beta2"
syngitv1beta2 "github.com/syngit-org/syngit/pkg/api/v1beta2"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/go-github v17.0.0+incompatible
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/syngit-org/syngit v0.2.1
github.com/syngit-org/syngit v0.3.0
golang.org/x/oauth2 v0.21.0
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syngit-org/syngit v0.2.1 h1:WDnF9qasE/CYkOVZWjnLRm6WMIytYZUm70eoqZW3zCo=
github.com/syngit-org/syngit v0.2.1/go.mod h1:y4pGzsw07EylMFasASfHSE0CNn2s3GtNtB+OpVIHOtU=
github.com/syngit-org/syngit v0.3.0 h1:gQpMh1PnxYoLAB/JLHpWmtQIvx6wEu9ehURhuo973k4=
github.com/syngit-org/syngit v0.3.0/go.mod h1:y4pGzsw07EylMFasASfHSE0CNn2s3GtNtB+OpVIHOtU=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
31 changes: 5 additions & 26 deletions internal/controller/remoteuser_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"context"
"fmt"
"maps"
"slices"

"github.com/google/go-github/github"
syngit "github.com/syngit-org/syngit/api/v1beta2"
syngit "github.com/syngit-org/syngit/pkg/api/v1beta2"
syngitutils "github.com/syngit-org/syngit/pkg/utils"
"golang.org/x/oauth2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -111,7 +111,7 @@ func (ruc *RemoteUserChecker) testConnection() {
conditions := ruc.remoteUser.Status.DeepCopy().Conditions

if ruc.remoteUser.Annotations["github.syngit.io/auth.test"] != "true" {
ruc.remoteUser.Status.Conditions = typeBasedConditionRemover(conditions, "Authenticated")
ruc.remoteUser.Status.Conditions = syngitutils.TypeBasedConditionRemover(conditions, "Authenticated")
} else {
if len(ruc.secret.Data) != 0 {
ctx := context.Background()
Expand All @@ -132,7 +132,7 @@ func (ruc *RemoteUserChecker) testConnection() {
}
ruc.remoteUser.Status.ConnexionStatus.Status = ""
ruc.remoteUser.Status.ConnexionStatus.Details = err.Error()
ruc.remoteUser.Status.Conditions = typeBasedConditionUpdater(conditions, condition)
ruc.remoteUser.Status.Conditions = syngitutils.TypeBasedConditionUpdater(conditions, condition)
} else {
condition := metav1.Condition{
Type: "Authenticated",
Expand All @@ -143,33 +143,12 @@ func (ruc *RemoteUserChecker) testConnection() {
}
ruc.remoteUser.Status.ConnexionStatus.Details = ""
ruc.remoteUser.Status.ConnexionStatus.Status = syngit.GitConnected
ruc.remoteUser.Status.Conditions = typeBasedConditionUpdater(conditions, condition)
ruc.remoteUser.Status.Conditions = syngitutils.TypeBasedConditionUpdater(conditions, condition)
}
}
}
}

func typeBasedConditionUpdater(conditions []metav1.Condition, condition metav1.Condition) []metav1.Condition {
conditions = typeBasedConditionRemover(conditions, condition.Type)
conditions = append(conditions, condition)

return conditions
}

func typeBasedConditionRemover(conditions []metav1.Condition, typeKind string) []metav1.Condition {
removeIndex := -1
for i, statusCondition := range conditions {
if typeKind == statusCondition.Type {
removeIndex = i
}
}
if removeIndex != -1 {
conditions = slices.Delete(conditions, removeIndex, removeIndex+1)
}

return conditions
}

func (r *RemoteUserReconciler) findObjectsForSecret(ctx context.Context, secret client.Object) []reconcile.Request {
attachedRemoteUsers := &syngit.RemoteUserList{}
listOps := &client.ListOptions{
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

syngitv1beta2 "github.com/syngit-org/syngit/api/v1beta2"
syngitv1beta2 "github.com/syngit-org/syngit/pkg/api/v1beta2"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down

0 comments on commit f686739

Please sign in to comment.