Skip to content

Commit

Permalink
feat(controller): apply WatchedNamespaces configuration item to manag…
Browse files Browse the repository at this point in the history
…er (#128)
  • Loading branch information
Alan-pad authored Jul 3, 2023
1 parent cff9a40 commit 6f83cfb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions internal/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -75,6 +76,7 @@ func (c *Controllers) Exec() {
HealthProbeBindAddress: c.config.Controller.HealthProbeBindAddress,
LeaderElection: c.config.Controller.LeaderElection.Enabled,
LeaderElectionID: c.config.Controller.LeaderElection.ID,
NewCache: cache.MultiNamespacedCacheBuilder(c.config.Controller.WatchedNamespaces),
})
if err != nil {
log.Fatalf("unable to start manager: %s", err)
Expand Down
24 changes: 17 additions & 7 deletions internal/controllers/terraformpullrequest/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,30 @@ func (r *Reconciler) getAffectedLayers(repository *configv1alpha1.TerraformRepos
}
affectedLayers := []configv1alpha1.TerraformLayer{}
for _, layer := range layers.Items {
if layer.Spec.Repository != pr.Spec.Repository {
continue
}
if layer.Spec.Branch != pr.Spec.Base {
continue
}
if layerFilesHaveChanged(layer, changes) {
if isLayerAffected(layer, *pr, changes) {
affectedLayers = append(affectedLayers, layer)
}
}

return affectedLayers, nil
}

func isLayerAffected(layer configv1alpha1.TerraformLayer, pr configv1alpha1.TerraformPullRequest, changes []string) bool {
if layer.Spec.Repository.Name != pr.Spec.Repository.Name {
return false
}
if layer.Spec.Repository.Namespace != pr.Spec.Repository.Namespace {
return false
}
if layer.Spec.Branch != pr.Spec.Base {
return false
}
if layerFilesHaveChanged(layer, changes) {
return true
}
return false
}

func generateTempLayers(pr *configv1alpha1.TerraformPullRequest, layers []configv1alpha1.TerraformLayer) []configv1alpha1.TerraformLayer {
list := []configv1alpha1.TerraformLayer{}
for _, layer := range layers {
Expand Down

0 comments on commit 6f83cfb

Please sign in to comment.