Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 78-enhancement-suspen…
Browse files Browse the repository at this point in the history
…d-resume-buttons
  • Loading branch information
laszlocph committed Apr 8, 2024
2 parents a32e360 + 9df18da commit a7fabf1
Show file tree
Hide file tree
Showing 24 changed files with 414 additions and 136 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ spec:
url: oci://ghcr.io/gimlet-io/capacitor-manifests
ref:
semver: ">=0.1.0"
verify:
provider: cosign
matchOIDCIdentity:
- issuer: "https://token.actions.githubusercontent.com"
subject: "^https://github.com/gimlet-io/capacitor.*$"
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
Expand Down
4 changes: 4 additions & 0 deletions cmd/capacitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func main() {
runController(err, ociRepositoryController, stopCh)
bucketController, err := controllers.BucketController(client, dynamicClient, clientHub)
runController(err, bucketController, stopCh)
helmRepositoryController, err := controllers.HelmRepositoryController(client, dynamicClient, clientHub)
runController(err, helmRepositoryController, stopCh)
helmChartController, err := controllers.HelmChartController(client, dynamicClient, clientHub)
runController(err, helmChartController, stopCh)
kustomizationController, err := controllers.KustomizeController(client, dynamicClient, clientHub)
runController(err, kustomizationController, stopCh)
helmReleaseController, err := controllers.HelmReleaseController(client, dynamicClient, clientHub)
Expand Down
2 changes: 2 additions & 0 deletions deploy/k8s/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rules:
- gitrepositories
- ocirepositories
- buckets
- helmrepositories
- helmcharts
- kustomizations
- helmreleases
verbs:
Expand Down
54 changes: 54 additions & 0 deletions pkg/controllers/helmChartController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package controllers

import (
"encoding/json"

"github.com/gimlet-io/capacitor/pkg/flux"
"github.com/gimlet-io/capacitor/pkg/streaming"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
)

var helmChartResource = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmcharts",
}

func HelmChartController(
client *kubernetes.Clientset,
dynamicClient *dynamic.DynamicClient,
clientHub *streaming.ClientHub,
) (*Controller, error) {
return NewDynamicController(
"helmcharts.source.toolkit.fluxcd.io",
dynamicClient,
helmChartResource,
func(informerEvent Event, objectMeta metav1.ObjectMeta, obj interface{}) error {
switch informerEvent.eventType {
case "create":
fallthrough
case "update":
fallthrough
case "delete":
fluxState, err := flux.State(client, dynamicClient)
if err != nil {
logrus.Warnf("could not get flux state: %s", err)
return nil
}
fluxStateBytes, err := json.Marshal(streaming.Envelope{
Type: streaming.FLUX_STATE_RECEIVED,
Payload: fluxState,
})
if err != nil {
logrus.Warnf("could not marshal event: %s", err)
return nil
}
clientHub.Broadcast <- fluxStateBytes
}
return nil
})
}
54 changes: 54 additions & 0 deletions pkg/controllers/helmRepositoryController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package controllers

import (
"encoding/json"

"github.com/gimlet-io/capacitor/pkg/flux"
"github.com/gimlet-io/capacitor/pkg/streaming"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
)

var helmRepositoryResource = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmrepositories",
}

func HelmRepositoryController(
client *kubernetes.Clientset,
dynamicClient *dynamic.DynamicClient,
clientHub *streaming.ClientHub,
) (*Controller, error) {
return NewDynamicController(
"helmrepositories.source.toolkit.fluxcd.io",
dynamicClient,
helmRepositoryResource,
func(informerEvent Event, objectMeta metav1.ObjectMeta, obj interface{}) error {
switch informerEvent.eventType {
case "create":
fallthrough
case "update":
fallthrough
case "delete":
fluxState, err := flux.State(client, dynamicClient)
if err != nil {
logrus.Warnf("could not get flux state: %s", err)
return nil
}
fluxStateBytes, err := json.Marshal(streaming.Envelope{
Type: streaming.FLUX_STATE_RECEIVED,
Payload: fluxState,
})
if err != nil {
logrus.Warnf("could not marshal event: %s", err)
return nil
}
clientHub.Broadcast <- fluxStateBytes
}
return nil
})
}
58 changes: 52 additions & 6 deletions pkg/flux/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ var (
Version: "v2beta1",
Resource: "helmreleases",
}

helmRepositoryGVR = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmrepositories",
}

helmChartGVR = schema.GroupVersionResource{
Group: "source.toolkit.fluxcd.io",
Version: "v1beta2",
Resource: "helmcharts",
}
)

func helmServices(dc *dynamic.DynamicClient) ([]Service, error) {
Expand Down Expand Up @@ -336,12 +348,14 @@ func helmStatusWithResources(

func State(c *kubernetes.Clientset, dc *dynamic.DynamicClient) (*FluxState, error) {
fluxState := &FluxState{
GitRepositories: []sourcev1.GitRepository{},
OCIRepositories: []sourcev1beta2.OCIRepository{},
Buckets: []sourcev1beta2.Bucket{},
Kustomizations: []kustomizationv1.Kustomization{},
HelmReleases: []helmv2beta2.HelmRelease{},
FluxServices: []Service{},
GitRepositories: []sourcev1.GitRepository{},
OCIRepositories: []sourcev1beta2.OCIRepository{},
Buckets: []sourcev1beta2.Bucket{},
Kustomizations: []kustomizationv1.Kustomization{},
HelmReleases: []helmv2beta2.HelmRelease{},
HelmRepositories: []sourcev1beta2.HelmRepository{},
HelmCharts: []sourcev1beta2.HelmChart{},
FluxServices: []Service{},
}

gitRepositories, err := dc.Resource(gitRepositoryGVR).
Expand Down Expand Up @@ -442,6 +456,38 @@ func State(c *kubernetes.Clientset, dc *dynamic.DynamicClient) (*FluxState, erro
fluxState.HelmReleases = append(fluxState.HelmReleases, helmRelease)
}

helmRepositories, err := dc.Resource(helmRepositoryGVR).
Namespace("").
List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
for _, h := range helmRepositories.Items {
unstructured := h.UnstructuredContent()
var helmRepository sourcev1beta2.HelmRepository
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructured, &helmRepository)
if err != nil {
return nil, err
}
fluxState.HelmRepositories = append(fluxState.HelmRepositories, helmRepository)
}

helmCharts, err := dc.Resource(helmChartGVR).
Namespace("").
List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
for _, h := range helmCharts.Items {
unstructured := h.UnstructuredContent()
var helmChart sourcev1beta2.HelmChart
err = runtime.DefaultUnstructuredConverter.FromUnstructured(unstructured, &helmChart)
if err != nil {
return nil, err
}
fluxState.HelmCharts = append(fluxState.HelmCharts, helmChart)
}

fluxServices, err := fluxServicesWithDetails(c)
if err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions pkg/flux/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ func NewReconcileCommand(resource string) *reconcileCommand {
groupVersion: sourcev1beta2.GroupVersion,
kind: sourcev1beta2.BucketKind,
}
case sourcev1beta2.HelmRepositoryKind:
return &reconcileCommand{
object: helmRepositoryAdapter{&sourcev1beta2.HelmRepository{}},
groupVersion: sourcev1beta2.GroupVersion,
kind: sourcev1beta2.HelmRepositoryKind,
}
case sourcev1beta2.HelmChartKind:
return &reconcileCommand{
object: helmChartAdapter{&sourcev1beta2.HelmChart{}},
groupVersion: sourcev1beta2.GroupVersion,
kind: sourcev1beta2.HelmChartKind,
}
}

return nil
Expand Down
40 changes: 40 additions & 0 deletions pkg/flux/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,43 @@ func (a bucketListAdapter) item(i int) suspendable {
func (a bucketListAdapter) resumeItem(i int) resumable {
return &bucketAdapter{&a.BucketList.Items[i]}
}

type helmRepositoryAdapter struct {
*sourcev1beta2.HelmRepository
}

func (a helmRepositoryAdapter) asClientObject() client.Object {
return a.HelmRepository
}

func (obj helmRepositoryAdapter) isSuspended() bool {
return obj.HelmRepository.Spec.Suspend
}

func (obj helmRepositoryAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}

func (obj helmRepositoryAdapter) successMessage() string {
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
}

type helmChartAdapter struct {
*sourcev1beta2.HelmChart
}

func (a helmChartAdapter) asClientObject() client.Object {
return a.HelmChart
}

func (obj helmChartAdapter) isSuspended() bool {
return obj.HelmChart.Spec.Suspend
}

func (obj helmChartAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}

func (obj helmChartAdapter) successMessage() string {
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
}
14 changes: 8 additions & 6 deletions pkg/flux/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import (
)

type FluxState struct {
GitRepositories []sourcev1.GitRepository `json:"gitRepositories"`
OCIRepositories []sourcev1beta2.OCIRepository `json:"ociRepositories"`
Buckets []sourcev1beta2.Bucket `json:"buckets"`
Kustomizations []kustomizationv1.Kustomization `json:"kustomizations"`
HelmReleases []helmv2beta2.HelmRelease `json:"helmReleases"`
FluxServices []Service `json:"fluxServices"`
GitRepositories []sourcev1.GitRepository `json:"gitRepositories"`
OCIRepositories []sourcev1beta2.OCIRepository `json:"ociRepositories"`
Buckets []sourcev1beta2.Bucket `json:"buckets"`
Kustomizations []kustomizationv1.Kustomization `json:"kustomizations"`
HelmReleases []helmv2beta2.HelmRelease `json:"helmReleases"`
HelmRepositories []sourcev1beta2.HelmRepository `json:"helmRepositories"`
HelmCharts []sourcev1beta2.HelmChart `json:"helmCharts"`
FluxServices []Service `json:"fluxServices"`
}

type Service struct {
Expand Down
29 changes: 3 additions & 26 deletions web/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,17 @@ function App() {
localStorage.setItem("filters", JSON.stringify(filters));
}, [filters]);

const addFilter = (filter) => {
setFilters([...filters, filter]);
}

const filterValueByProperty = (property) => {
const filter = filters.find(f => f.property === property)
if (!filter) {
return ""
}

return filter.value
}

const deleteFilter = (filter) => {
setFilters(filters.filter(f => f.property !== filter.property))
}

const resetFilters = () => {
setFilters([])
}

return (
<>
<APIBackend capacitorClient={capacitorClient} store={store}/>
<StreamingBackend capacitorClient={capacitorClient} store={store}/>
<ToastNotifications store={store} handleNavigationSelect={handleNavigationSelect} />
<div className="max-w-6xl mx-auto">
<div className="my-16">
<FilterBar
<FilterBar
properties={["Service", "Namespace", "Domain"]}
filters={filters}
addFilter={addFilter}
deleteFilter={deleteFilter}
resetFilters={resetFilters}
filterValueByProperty={filterValueByProperty}
change={setFilters}
/>
</div>
<div className="grid grid-cols-1 gap-y-4 pb-32">
Expand Down
2 changes: 1 addition & 1 deletion web/src/ExpandedFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function ExpandedFooter(props) {
<HelmReleases capacitorClient={client} helmReleases={fluxState.helmReleases} targetReference={targetReference} handleNavigationSelect={handleNavigationSelect} />
}
{selected === "Sources" &&
<Sources capacitorClient={client} fluxState={fluxState} targetReference={targetReference} />
<Sources capacitorClient={client} fluxState={fluxState} targetReference={targetReference} handleNavigationSelect={handleNavigationSelect} />
}
{selected === "Flux Runtime" &&
<CompactServices capacitorClient={client} store={store} services={fluxState.fluxServices} />
Expand Down
Loading

0 comments on commit a7fabf1

Please sign in to comment.