Skip to content

Commit

Permalink
feat: Create new app for Gateway API (#3057)
Browse files Browse the repository at this point in the history
* feat: Create new app for Gateway API

* feat: Create new app for Gateway API

* feat: Work on comment

* feat: api version correction

* build: Updated .github/service-labeler.yaml

* feat: api version correction

* feat: Add independent management of Traefik CRDs

* feat: update kustomization.yaml

* feat: worked on comment

* feat: include list-images-values.yaml

* feat: update the dir structure

* feat: worked on comment

* feat: kustomization file update

* feat: kustomization file update

* feat: apiversion update

* feat: changed the logic in apptests

* feat: skip crds installtion

* feat: Add CRDs installation in apptests

* feat: Add traefik crd as dependency

* feat: used absolutepath function

* feat: corrected gateway api path

* feat: Added default CM

* feat: path correction

* feat: print path to check

* feat: corrected path

* feat: worked on comment

* feat: changed the name as per comment

* fix(harbor): add gateway-api-crds default app

* fix: add gateway-api-crds metadata

* fix: install gateway-api crds on new version

* fix: avoid adding same traefik override

* fix: trigger reconciliation

* fix: increse wait interval

---------

Co-authored-by: d2iq-mergebot <[email protected]>
Co-authored-by: Martin Hrabovcin <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent c173ba9 commit 6b63047
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 201 deletions.
4 changes: 4 additions & 0 deletions .github/service-labeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ services/gatekeeper:
- changed-files:
- any-glob-to-any-file:
- services/gatekeeper/**
services/gateway-api-crds:
- changed-files:
- any-glob-to-any-file:
- services/gateway-api-crds/**
services/git-operator:
- changed-files:
- any-glob-to-any-file:
Expand Down
81 changes: 40 additions & 41 deletions apptests/appscenarios/traefik.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ package appscenarios
import (
"context"
"fmt"
"os"
"path/filepath"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
controllerruntime "sigs.k8s.io/controller-runtime"
ctrlClient "sigs.k8s.io/controller-runtime/pkg/client"

fluxhelmv2beta2 "github.com/fluxcd/helm-controller/api/v2beta2"
"github.com/mesosphere/kommander-applications/apptests/constants"
"github.com/mesosphere/kommander-applications/apptests/environment"
"github.com/mesosphere/kommander-applications/apptests/flux"
)

type traefik struct {
Expand Down Expand Up @@ -58,51 +52,56 @@ func (t traefik) install(ctx context.Context, env *environment.Env, appPath stri
if err != nil {
return err
}
// apply the rest of kustomizations
err = env.ApplyKustomizations(ctx, appPath, map[string]string{
"releaseNamespace": kommanderNamespace,
"workspaceNamespace": kommanderNamespace,
})
if err != nil {
return err
}

traefikCMName := "traefik-overrides"
err = t.applyTraefikOverrideCM(ctx, env, traefikCMName)
if err != nil {
return err
}

hr := &fluxhelmv2beta2.HelmRelease{
TypeMeta: metav1.TypeMeta{
Kind: fluxhelmv2beta2.HelmReleaseKind,
APIVersion: fluxhelmv2beta2.GroupVersion.Version,
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.Traefik,
Namespace: kommanderNamespace,
},
}
// apply the rest of kustomizations
traefikDir := filepath.Join(appPath, "traefik")
if _, err := os.Stat(traefikDir); !os.IsNotExist(err) {
// Find the correct versioned path for gateway-api-crds
gatewayCRDsPath, err := absolutePathTo("gateway-api-crds") // Ensure the correct version is used
if err != nil {
return fmt.Errorf("failed to get path for gateway-api-crds: %w", err)
}

// Apply defaults for gateway-api-crds
err = env.ApplyKustomizations(ctx, filepath.Join(gatewayCRDsPath, "/defaults"), map[string]string{
"releaseNamespace": kommanderNamespace,
})
if err != nil {
return fmt.Errorf("failed to apply defaults for gateway-api-crds: %w", err)
}

genericClient, err := ctrlClient.New(env.K8sClient.Config(), ctrlClient.Options{
Scheme: flux.NewScheme(),
})
if err != nil {
return fmt.Errorf("could not create the generic client: %w", err)
// Install gateway-api-crds
err = env.ApplyKustomizations(ctx, gatewayCRDsPath, map[string]string{
"releaseNamespace": kommanderNamespace,
})
if err != nil {
return fmt.Errorf("failed to apply gateway-api CRDs: %w", err)
}

// If the traefik directory exists, apply both `crds` and `traefik` subdirectories
for _, dir := range []string{"crds", "traefik"} {
subDir := filepath.Join(appPath, dir)
err := env.ApplyKustomizations(ctx, subDir, map[string]string{
"releaseNamespace": kommanderNamespace,
"workspaceNamespace": kommanderNamespace,
})
if err != nil {
return err
}
}
}

err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
_, err = controllerruntime.CreateOrUpdate(ctx, genericClient, hr, func() error {
hr.Spec.ValuesFrom = append(hr.Spec.ValuesFrom, fluxhelmv2beta2.ValuesReference{
Kind: "ConfigMap",
Name: traefikCMName,
})
return nil
})
return err
// If the `traefik` directory doesn't exist, apply the default (root) kustomizations
return env.ApplyKustomizations(ctx, appPath, map[string]string{
"releaseNamespace": kommanderNamespace,
"workspaceNamespace": kommanderNamespace,
})

return err
}

func (t traefik) applyTraefikOverrideCM(ctx context.Context, env *environment.Env, cmName string) error {
Expand Down
19 changes: 18 additions & 1 deletion apptests/appscenarios/traefik_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/net"
"k8s.io/client-go/util/retry"
controllerruntime "sigs.k8s.io/controller-runtime"
ctrlClient "sigs.k8s.io/controller-runtime/pkg/client"

fluxhelmv2beta2 "github.com/fluxcd/helm-controller/api/v2beta2"
Expand Down Expand Up @@ -202,12 +204,27 @@ var _ = Describe("Traefik Tests", Label("traefik"), func() {
Expect(cl.Delete(ctx, dashboardIngress)).To(Succeed())
})

By("triggering a HelmRelease reconciliation", func() {
Expect(
retry.RetryOnConflict(retry.DefaultRetry, func() error {
_, err = controllerruntime.CreateOrUpdate(ctx, k8sClient, hr, func() error {
if hr.Annotations == nil {
hr.Annotations = map[string]string{}
}
hr.Annotations["reconcile.fluxcd.io/requestedAt"] = time.Now().Format(time.RFC3339)
return nil
})
return err
}),
).To(Succeed())
})

// Check the status of the HelmReleases
By("waiting for HR to get upgraded")
Eventually(func() (*fluxhelmv2beta2.HelmRelease, error) {
err := k8sClient.Get(ctx, ctrlClient.ObjectKeyFromObject(hr), hr)
return hr, err
}, "30s", pollInterval).Should(And(
}, "1m", pollInterval).Should(And(
HaveField("Status.ObservedGeneration", BeNumerically(">", existingGeneration)),
HaveField("Status.Conditions", ContainElement(And(
HaveField("Type", Equal(apimeta.ReadyCondition)),
Expand Down
12 changes: 12 additions & 0 deletions services/gateway-api-crds/1.2.0/defaults/cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: gateway-api-1.2.0-d2iq-defaults
namespace: ${releaseNamespace}
data:
values.yaml: |
# values.yaml content to enable only Gateway API CRDs installation
gatewayAPI: true
traefik: false
hub: false
deleteOnUninstall: false
4 changes: 4 additions & 0 deletions services/gateway-api-crds/1.2.0/defaults/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- cm.yaml
18 changes: 18 additions & 0 deletions services/gateway-api-crds/1.2.0/gateway-api-crds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: gateway-api-crds
namespace: ${releaseNamespace}
spec:
interval: 6h
chart:
spec:
chart: traefik-crds
version: "1.2.0" # Use the appropriate version for Traefik CRDs
sourceRef:
kind: HelmRepository
name: helm.traefik.io-traefik
namespace: kommander-flux
valuesFrom:
- kind: ConfigMap
name: gateway-api-1.2.0-d2iq-defaults
4 changes: 4 additions & 0 deletions services/gateway-api-crds/1.2.0/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- gateway-api-crds.yaml
9 changes: 9 additions & 0 deletions services/gateway-api-crds/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: internal
scope:
- workspace
licensing:
- Starter
- Pro
- Ultimate
- Essential
- Enterprise
1 change: 1 addition & 0 deletions services/kommander/0.14.0/defaults/cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ data:
prerequisites:
defaultApps:
- "reloader"
- "gateway-api-crds"
- "traefik"
- "kubernetes-dashboard"
- "kubecost"
Expand Down
23 changes: 23 additions & 0 deletions services/traefik/34.1.0/crds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: traefik-crd-helmrelease
namespace: ${releaseNamespace}
spec:
force: false
prune: true
wait: true
interval: 6h
retryInterval: 1m
path: ./services/traefik/34.1.0/crds
sourceRef:
kind: GitRepository
name: management
namespace: kommander-flux
timeout: 1m
postBuild:
substitute:
releaseNamespace: ${releaseNamespace}
substituteFrom:
- kind: ConfigMap
name: substitution-vars
18 changes: 18 additions & 0 deletions services/traefik/34.1.0/crds/crds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: traefik-crds
namespace: ${releaseNamespace}
spec:
interval: 6h
chart:
spec:
chart: traefik-crds
version: "1.2.0" # Use the appropriate version for Traefik CRDs
sourceRef:
kind: HelmRepository
name: helm.traefik.io-traefik
namespace: kommander-flux
valuesFrom:
- kind: ConfigMap
name: traefik-crd-1.2.0-d2iq-defaults
4 changes: 4 additions & 0 deletions services/traefik/34.1.0/crds/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- crds.yaml
4 changes: 4 additions & 0 deletions services/traefik/34.1.0/crds/list-images-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gatewayAPI: false
traefik: true
hub: false
deleteOnUninstall: false
12 changes: 12 additions & 0 deletions services/traefik/34.1.0/defaults/crds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: traefik-crd-1.2.0-d2iq-defaults
namespace: ${releaseNamespace}
data:
values.yaml: |
# values.yaml content to enable only Gateway API CRDs installation
gatewayAPI: false
traefik: true
hub: false
deleteOnUninstall: false
3 changes: 2 additions & 1 deletion services/traefik/34.1.0/defaults/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- cm.yaml
- traefik.yaml
- crds.yaml
File renamed without changes.
1 change: 1 addition & 0 deletions services/traefik/34.1.0/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ kind: Kustomization
resources:
- traefik.yaml
- grafana-dashboards
- crds.yaml
Loading

0 comments on commit 6b63047

Please sign in to comment.