Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run kpack-image-builder, job-task-runner and statefulset-runner as standalone Deployments #3522

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,51 @@ A sample VSCode `launch.json` configuration is provided below:
],
"host": "localhost",
"port": 30052
},
{
"name": "Attach to Debug Job Task Runner on Kind",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "attach",
"mode": "remote",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/workspace"
}
],
"host": "localhost",
"port": 30053
},
{
"name": "Attach to Debug Kpack Image Builder on Kind",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "attach",
"mode": "remote",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/workspace"
}
],
"host": "localhost",
"port": 30054
},
{
"name": "Attach to Debug Statefulset Runner on Kind",
"type": "go",
"debugAdapter": "dlv-dap",
"request": "attach",
"mode": "remote",
"substitutePath": [
{
"from": "${workspaceFolder}",
"to": "/workspace"
}
],
"host": "localhost",
"port": 30055
}
]
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ RUN --mount=type=cache,target=/go/pkg/mod \

COPY model model
COPY controllers controllers
COPY kpack-image-builder kpack-image-builder
COPY job-task-runner job-task-runner
COPY statefulset-runner statefulset-runner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are splitting the statefulset-runner into its own deployment with its own docker image this line should go.

Currently if it is removed there are compilation errors, because controllers refer to a constant defined by statefulset-runner. However this constant is a duplicate so we car simply refer to the one in the korifi types. With this change we should be able to get rid of statefulset-runner in the controllers Dockerfile.

COPY tools tools
COPY version version
Expand Down
28 changes: 1 addition & 27 deletions controllers/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
)

type ControllerConfig struct {
// components
IncludeKpackImageBuilder bool `yaml:"includeKpackImageBuilder"`
IncludeJobTaskRunner bool `yaml:"includeJobTaskRunner"`
IncludeStatefulsetRunner bool `yaml:"includeStatefulsetRunner"`

// core controllers
CFProcessDefaults CFProcessDefaults `yaml:"cfProcessDefaults"`
CFStagingResources CFStagingResources `yaml:"cfStagingResources"`
Expand All @@ -29,16 +24,7 @@ type ControllerConfig struct {
LogLevel zapcore.Level `yaml:"logLevel"`
SpaceFinalizerAppDeletionTimeout *int32 `yaml:"spaceFinalizerAppDeletionTimeout"`

// job-task-runner
JobTTL string `yaml:"jobTTL"`

// kpack-image-builder
ClusterBuilderName string `yaml:"clusterBuilderName"`
BuilderServiceAccount string `yaml:"builderServiceAccount"`
BuilderReadinessTimeout string `yaml:"builderReadinessTimeout"`
ContainerRepositoryPrefix string `yaml:"containerRepositoryPrefix"`
ContainerRegistryType string `yaml:"containerRegistryType"`
Networking Networking `yaml:"networking"`
Networking Networking `yaml:"networking"`

ExperimentalManagedServicesEnabled bool `yaml:"experimentalManagedServicesEnabled"`
TrustInsecureServiceBrokers bool `yaml:"trustInsecureServiceBrokers"`
Expand Down Expand Up @@ -106,15 +92,3 @@ func (c ControllerConfig) ParseTaskTTL() (time.Duration, error) {

return tools.ParseDuration(c.TaskTTL)
}

func (c ControllerConfig) ParseBuilderReadinessTimeout() (time.Duration, error) {
return tools.ParseDuration(c.BuilderReadinessTimeout)
}

func (c ControllerConfig) ParseJobTTL() (time.Duration, error) {
if c.JobTTL == "" {
return defaultJobTTL, nil
}

return tools.ParseDuration(c.JobTTL)
}
47 changes: 0 additions & 47 deletions controllers/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ var _ = Describe("LoadFromPath", func() {
TaskTTL: "taskTTL",
BuilderName: "buildReconciler",
RunnerName: "statefulset-runner",
JobTTL: "jobTTL",
LogLevel: zapcore.DebugLevel,
SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int32(42)),
Networking: config.Networking{
Expand Down Expand Up @@ -89,7 +88,6 @@ var _ = Describe("LoadFromPath", func() {
RunnerName: "statefulset-runner",
NamespaceLabels: map[string]string{},
ExtraVCAPApplicationValues: map[string]any{},
JobTTL: "jobTTL",
LogLevel: zapcore.DebugLevel,
SpaceFinalizerAppDeletionTimeout: tools.PtrTo(int32(42)),
Networking: config.Networking{
Expand Down Expand Up @@ -187,48 +185,3 @@ var _ = Describe("ParseTaskTTL", func() {
})
})
})

var _ = Describe("ParseJobTTL", func() {
var (
jobTTL time.Duration
parseErr error
jobTTLStr string
)

BeforeEach(func() {
jobTTLStr = ""
})

JustBeforeEach(func() {
cfg := config.ControllerConfig{
JobTTL: jobTTLStr,
}
jobTTL, parseErr = cfg.ParseJobTTL()
})

It("return 30 days by default", func() {
Expect(parseErr).NotTo(HaveOccurred())
Expect(jobTTL).To(Equal(24 * time.Hour))
})

When("jobTTL is something parseable by tools.ParseDuration", func() {
BeforeEach(func() {
jobTTLStr = "5d12h"
})

It("parses ok", func() {
Expect(parseErr).NotTo(HaveOccurred())
Expect(jobTTL).To(Equal(5*24*time.Hour + 12*time.Hour))
})
})

When("entering something that cannot be parsed", func() {
BeforeEach(func() {
jobTTLStr = "foreva"
})

It("returns an error", func() {
Expect(parseErr).To(HaveOccurred())
})
})
})
2 changes: 2 additions & 0 deletions controllers/controllers/workloads/orgs/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (r *Reconciler) enqueueCFOrgRequests(ctx context.Context, object client.Obj
//+kubebuilder:rbac:groups="metrics.k8s.io",resources=pods,verbs=get;list;watch
//+kubebuilder:rbac:groups="policy",resources=poddisruptionbudgets,verbs=create;deletecollection
//+kubebuilder:rbac:groups="policy",resources=podsecuritypolicies,verbs=use
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=runnerinfos,verbs=get;list;watch;create;patch;delete
//+kubebuilder:rbac:groups=korifi.cloudfoundry.org,resources=runnerinfos/status,verbs=get;patch

func (r *Reconciler) ReconcileResource(ctx context.Context, cfOrg *korifiv1alpha1.CFOrg) (ctrl.Result, error) {
nsReconcileResult, err := r.namespaceReconciler.ReconcileResource(ctx, cfOrg)
Expand Down
94 changes: 0 additions & 94 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ import (
packageswebhook "code.cloudfoundry.org/korifi/controllers/webhooks/workloads/packages"
spaceswebhook "code.cloudfoundry.org/korifi/controllers/webhooks/workloads/spaces"
taskswebhook "code.cloudfoundry.org/korifi/controllers/webhooks/workloads/tasks"
jobtaskrunnercontrollers "code.cloudfoundry.org/korifi/job-task-runner/controllers"
"code.cloudfoundry.org/korifi/kpack-image-builder/controllers"
kpackimagebuilderfinalizer "code.cloudfoundry.org/korifi/kpack-image-builder/controllers/webhooks/finalizer"
statefulsetcontrollers "code.cloudfoundry.org/korifi/statefulset-runner/controllers"
"code.cloudfoundry.org/korifi/tools"
"code.cloudfoundry.org/korifi/tools/image"
"code.cloudfoundry.org/korifi/tools/registry"
"code.cloudfoundry.org/korifi/version"

buildv1alpha2 "github.com/pivotal/kpack/pkg/apis/build/v1alpha2"
Expand Down Expand Up @@ -344,91 +339,6 @@ func main() {
os.Exit(1)
}

if controllerConfig.IncludeKpackImageBuilder {
var builderReadinessTimeout time.Duration
builderReadinessTimeout, err = controllerConfig.ParseBuilderReadinessTimeout()
if err != nil {
setupLog.Error(err, "error parsing builderReadinessTimeout")
os.Exit(1)
}
if err = controllers.NewBuildWorkloadReconciler(
mgr.GetClient(),
mgr.GetScheme(),
controllersLog,
controllerConfig,
imageClient,
controllerConfig.ContainerRepositoryPrefix,
registry.NewRepositoryCreator(controllerConfig.ContainerRegistryType),
builderReadinessTimeout,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BuildWorkload")
os.Exit(1)
}

if err = controllers.NewBuilderInfoReconciler(
mgr.GetClient(),
mgr.GetScheme(),
controllersLog,
controllerConfig.ClusterBuilderName,
controllerConfig.CFRootNamespace,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BuilderInfo")
os.Exit(1)
}

if err = controllers.NewKpackBuildController(
mgr.GetClient(),
controllersLog,
imageClient,
controllerConfig.BuilderServiceAccount,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KpackBuild")
os.Exit(1)
}
}

if controllerConfig.IncludeJobTaskRunner {
var jobTTL time.Duration
jobTTL, err = controllerConfig.ParseJobTTL()
if err != nil {
panic(err)
}

taskWorkloadReconciler := jobtaskrunnercontrollers.NewTaskWorkloadReconciler(
controllersLog,
mgr.GetClient(),
mgr.GetScheme(),
jobtaskrunnercontrollers.NewStatusGetter(mgr.GetClient()),
jobTTL,
)
if err = taskWorkloadReconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "TaskWorkload")
os.Exit(1)
}
}

if controllerConfig.IncludeStatefulsetRunner {
if err = statefulsetcontrollers.NewAppWorkloadReconciler(
mgr.GetClient(),
mgr.GetScheme(),
statefulsetcontrollers.NewAppWorkloadToStatefulsetConverter(mgr.GetScheme()),
statefulsetcontrollers.NewPDBUpdater(mgr.GetClient()),
controllersLog,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AppWorkload")
os.Exit(1)
}

if err = statefulsetcontrollers.NewRunnerInfoReconciler(
mgr.GetClient(),
mgr.GetScheme(),
controllersLog,
).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "RunnerInfo")
os.Exit(1)
}
}

if err = routes.NewReconciler(
mgr.GetClient(),
mgr.GetScheme(),
Expand Down Expand Up @@ -560,10 +470,6 @@ func main() {
os.Exit(1)
}

if controllerConfig.IncludeKpackImageBuilder {
kpackimagebuilderfinalizer.NewKpackImageBuilderFinalizerWebhook().SetupWebhookWithManager(mgr)
}

if err = mgr.AddReadyzCheck("readyz", mgr.GetWebhookServer().StartedChecker()); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
Expand Down
2 changes: 0 additions & 2 deletions controllers/remote-debug/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ RUN --mount=type=cache,target=/go/pkg/mod \

COPY model model
COPY controllers controllers
COPY kpack-image-builder kpack-image-builder
COPY job-task-runner job-task-runner
COPY statefulset-runner statefulset-runner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should go, see above comment for more details.

COPY tools tools
COPY version version
Expand Down
19 changes: 0 additions & 19 deletions helm/korifi/controllers/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ metadata:
namespace: {{ .Release.Namespace }}
data:
config.yaml: |-
includeKpackImageBuilder: {{ .Values.kpackImageBuilder.include }}
includeJobTaskRunner: {{ .Values.jobTaskRunner.include }}
includeStatefulsetRunner: {{ .Values.statefulsetRunner.include }}
builderName: {{ .Values.reconcilers.build }}
runnerName: {{ .Values.reconcilers.run }}
cfProcessDefaults:
Expand Down Expand Up @@ -38,22 +35,6 @@ data:
maxRetainedPackagesPerApp: {{ .Values.controllers.maxRetainedPackagesPerApp }}
maxRetainedBuildsPerApp: {{ .Values.controllers.maxRetainedBuildsPerApp }}
logLevel: {{ .Values.logLevel }}
{{- if .Values.kpackImageBuilder.include }}
clusterBuilderName: {{ .Values.kpackImageBuilder.clusterBuilderName | default "cf-kpack-cluster-builder" }}
builderReadinessTimeout: {{ required "builderReadinessTimeout is required" .Values.kpackImageBuilder.builderReadinessTimeout }}
containerRepositoryPrefix: {{ .Values.containerRepositoryPrefix | quote }}
builderServiceAccount: kpack-service-account
cfStagingResources:
buildCacheMB: {{ .Values.stagingRequirements.buildCacheMB }}
diskMB: {{ .Values.stagingRequirements.diskMB }}
memoryMB: {{ .Values.stagingRequirements.memoryMB }}
{{- if .Values.eksContainerRegistryRoleARN }}
containerRegistryType: "ECR"
{{- end }}
{{- end }}
{{- if .Values.jobTaskRunner.include }}
jobTTL: {{ required "jobTTL is required" .Values.jobTaskRunner.jobTTL }}
{{- end }}
networking:
gatewayNamespace: {{ .Release.Namespace }}-gateway
gatewayName: korifi
Expand Down
48 changes: 0 additions & 48 deletions helm/korifi/controllers/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,51 +79,3 @@ subjects:
- kind: ServiceAccount
name: korifi-controllers-controller-manager
namespace: {{ .Release.Namespace }}

{{- if .Values.jobTaskRunner.include }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: korifi-job-task-runner-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: korifi-job-task-runner-taskworkload-manager-role
subjects:
- kind: ServiceAccount
name: korifi-controllers-controller-manager
namespace: {{ .Release.Namespace }}
{{- end }}

{{- if .Values.kpackImageBuilder.include }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: korifi-kpack-build-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: korifi-kpack-build-manager-role
subjects:
- kind: ServiceAccount
name: korifi-controllers-controller-manager
namespace: {{ .Release.Namespace }}
{{- end }}

{{- if .Values.statefulsetRunner.include }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: korifi-statefulset-runner-manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: korifi-statefulset-runner-appworkload-manager-role
subjects:
- kind: ServiceAccount
name: korifi-controllers-controller-manager
namespace: {{ .Release.Namespace }}
{{- end }}
Loading
Loading