Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak committed Mar 28, 2024
1 parent afc8ff7 commit eb201ba
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
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
})
}

0 comments on commit eb201ba

Please sign in to comment.