Skip to content

Commit

Permalink
fix permissions and reconcile issue
Browse files Browse the repository at this point in the history
Signed-off-by: Jeeva Kandasamy <[email protected]>
  • Loading branch information
jkandasa committed Jul 31, 2024
1 parent 2e2db8c commit d5eba0f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 30 deletions.
4 changes: 2 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
// The set of controllers this controller process runs.
"github.com/openshift-pipelines/tektoncd-pruner/pkg/reconciler/pipelinerun"
"github.com/openshift-pipelines/tektoncd-pruner/pkg/reconciler/taskrun"
// "github.com/openshift-pipelines/tektoncd-pruner/pkg/reconciler/taskrun"
"github.com/openshift-pipelines/tektoncd-pruner/pkg/reconciler/tektonpruner"

// This defines the shared main for injected controllers.
Expand All @@ -14,6 +14,6 @@ func main() {
sharedmain.Main("controller",
tektonpruner.NewController,
pipelinerun.NewController,
taskrun.NewController,
// taskrun.NewController,
)
}
12 changes: 12 additions & 0 deletions config/200-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rules:
- "pruner.tekton.dev"
resources:
- "tektonpruners"
- "tektonpruners/status"
- "tektonpruners/finalizers"
verbs:
- "get"
- "list"
Expand All @@ -20,6 +22,16 @@ rules:
- "patch"
- "watch"

# Write permissions to publish events.
- apiGroups:
- ""
resources:
- "events"
verbs:
- "create"
- "update"
- "patch"

# allows to manage taskruns and pipelineruns
- apiGroups:
- "tekton.dev"
Expand Down
13 changes: 0 additions & 13 deletions config/300-tektonpruner-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand All @@ -20,10 +19,6 @@ spec:
properties:
spec:
type: object
required:
- ttlSecondsAfterFinished
- successfulHistoryLimit
- failedHistoryLimit
properties:
failedHistoryLimit:
type: integer
Expand All @@ -32,10 +27,6 @@ spec:
type: array
items:
type: object
required:
- ttlSecondsAfterFinished
- successfulHistoryLimit
- failedHistoryLimit
properties:
failedHistoryLimit:
type: integer
Expand All @@ -55,10 +46,6 @@ spec:
type: array
items:
type: object
required:
- ttlSecondsAfterFinished
- successfulHistoryLimit
- failedHistoryLimit
properties:
failedHistoryLimit:
type: integer
Expand Down
2 changes: 1 addition & 1 deletion config/600-tekton-pruner-default-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ data:
- name: foo
ttlSecondsAfterFinished: 120 # 2 minutes
global-config: |
ttlSecondsAfterFinished: 600 # 10 minutes
ttlSecondsAfterFinished: 540 # 9 minutes
successfulHistoryLimit: 3
failedHistoryLimit: 1
2 changes: 1 addition & 1 deletion pkg/apis/tektonpruner/v1alpha1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ limitations under the License.
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:defaulter-gen=TypeMeta
// +groupName=openshiftpipelines.org
// +groupName=pruner.tekton.dev

package v1alpha1
26 changes: 17 additions & 9 deletions pkg/apis/tektonpruner/v1alpha1/tektonpruner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ const (

// TektonPrunerSpec defines the desired state of TektonPruner
type TektonPrunerSpec struct {
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished"`
SuccessfulHistoryLimit *int32 `json:"successfulHistoryLimit"`
FailedHistoryLimit *int32 `json:"failedHistoryLimit"`
Pipelines []ResourceSpec `json:"pipelines,omitempty"`
Tasks []ResourceSpec `json:"tasks,omitempty"`
// +optional
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
// +optional
SuccessfulHistoryLimit *int32 `json:"successfulHistoryLimit,omitempty"`
// +optional
FailedHistoryLimit *int32 `json:"failedHistoryLimit,omitempty"`
// +optional
Pipelines []ResourceSpec `json:"pipelines,omitempty"`
// +optional
Tasks []ResourceSpec `json:"tasks,omitempty"`
}

type ResourceSpec struct {
Name string `json:"name"`
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished"`
SuccessfulHistoryLimit *int32 `json:"successfulHistoryLimit"`
FailedHistoryLimit *int32 `json:"failedHistoryLimit"`
Name string `json:"name"`
// +optional
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
// +optional
SuccessfulHistoryLimit *int32 `json:"successfulHistoryLimit,omitempty"`
// +optional
FailedHistoryLimit *int32 `json:"failedHistoryLimit,omitempty"`
}

// TektonPrunerStatus defines the observed state of TektonPruner
Expand Down
2 changes: 2 additions & 0 deletions pkg/reconciler/helper/config_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (ps *_prunerStore) LoadOnStartup(ctx context.Context, client kubernetes.Int
ps.mutex.Lock()
defer ps.mutex.Unlock()

// logger := logging.FromContext(ctx)

defaultTTL := DefaultTTLSeconds
defaultSpec := &PrunerSpec{
TTLSecondsAfterFinished: &defaultTTL,
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/helper/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ const (

DefaultTTLSeconds = int32(600) // 60 * 10 = 10 minutes
DefaultConfigMapName = "tekton-pruner-default-spec"
DefaultConfigKey = "spec"
DefaultConfigKey = "global-config"
)
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
}

ctrlOptions := controller.Options{
FinalizerName: "pruner_ttl_controller",
FinalizerName: "pruner.tekton.dev/ttl",
}

impl := pipelinerunreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options { return ctrlOptions })
Expand Down
10 changes: 8 additions & 2 deletions pkg/reconciler/tektonpruner/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tektonpruner

import (
"context"
"os"

"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
Expand Down Expand Up @@ -33,14 +34,19 @@ func NewController(ctx context.Context, cmw configmap.Watcher) *controller.Impl
// The client will be needed to create/delete Pods via the API.
kubeclient: kubeclient.Get(ctx),
}
impl := tektonprunerreconciler.NewImpl(ctx, r)

ctrlOptions := controller.Options{
FinalizerName: "pruner.tekton.dev/tektonpruner",
}

impl := tektonprunerreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options { return ctrlOptions })

// Listen for events on the main resource and enqueue themselves.
tektonPrunerInformer.Informer().AddEventHandler(controller.HandleAll(impl.Enqueue))

// load pruner store
// TODO: update the namespace dynamically
helper.PrunerConfigStore.LoadOnStartup(ctx, r.kubeclient, "test")
helper.PrunerConfigStore.LoadOnStartup(ctx, r.kubeclient, os.Getenv("SYSTEM_NAMESPACE"))

return impl
}

0 comments on commit d5eba0f

Please sign in to comment.