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

Closed
Closed
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
3 changes: 0 additions & 3 deletions controllers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +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 tools tools
COPY version version

Expand Down
3 changes: 1 addition & 2 deletions controllers/cleanup/build_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sort"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -35,7 +34,7 @@ func (c BuildCleaner) Clean(ctx context.Context, app types.NamespacedName) error
err = c.k8sClient.List(ctx, &cfBuilds,
client.InNamespace(app.Namespace),
client.MatchingLabels{
controllers.LabelAppGUID: app.Name,
korifiv1alpha1.CFAppGUIDLabelKey: app.Name,
},
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions controllers/cleanup/build_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/controllers/cleanup"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -108,7 +107,7 @@ func createBuild(namespace, appGUID, name string) *korifiv1alpha1.CFBuild {
Name: name,
Namespace: namespace,
Labels: map[string]string{
controllers.LabelAppGUID: appGUID,
korifiv1alpha1.CFAppGUIDLabelKey: appGUID,
},
},
Spec: korifiv1alpha1.CFBuildSpec{Lifecycle: korifiv1alpha1.Lifecycle{Type: "buildpack"}},
Expand Down
3 changes: 1 addition & 2 deletions controllers/cleanup/package_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"sort"

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (c PackageCleaner) Clean(ctx context.Context, app types.NamespacedName) err
err = c.k8sClient.List(ctx, &cfPackages,
client.InNamespace(app.Namespace),
client.MatchingLabels{
controllers.LabelAppGUID: app.Name,
korifiv1alpha1.CFAppGUIDLabelKey: app.Name,
},
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions controllers/cleanup/package_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
"code.cloudfoundry.org/korifi/controllers/cleanup"
"code.cloudfoundry.org/korifi/statefulset-runner/controllers"

"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -119,7 +118,7 @@ func createPackage(namespace, appGUID, name string) *korifiv1alpha1.CFPackage {
Name: name,
Namespace: namespace,
Labels: map[string]string{
controllers.LabelAppGUID: appGUID,
korifiv1alpha1.CFAppGUIDLabelKey: appGUID,
},
},
Spec: korifiv1alpha1.CFPackageSpec{Type: "bits"},
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 @@ -62,13 +62,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 @@ -345,91 +340,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 @@ -563,10 +473,6 @@ func main() {

relationships.NewSpaceGUIDWebhook().SetupWebhookWithManager(mgr)

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
3 changes: 0 additions & 3 deletions controllers/remote-debug/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +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 tools tools
COPY version version

Expand Down
Loading
Loading