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

Implement lifecycle CRD #1628

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e693700
Add (preliminary) ClusterLifecycle types
natalieparellano May 7, 2024
e087af5
Run hack/update-codegen.sh
natalieparellano May 7, 2024
72b48e5
Run hack/openapi-codegen.sh
natalieparellano May 7, 2024
4541b20
Add CustomResourceDefinition
natalieparellano May 7, 2024
224d677
Update config/controllerrole.yaml
natalieparellano May 8, 2024
a98af34
Update cmd/controller/main.go to provide lifecycle informer to builde…
natalieparellano May 8, 2024
adfd3ac
Add lifecycle version to build status
natalieparellano May 8, 2024
776756c
Populate lifecycle version (for build status) in build metadata
natalieparellano May 8, 2024
622650f
Register ClusterLifecycle types
natalieparellano May 8, 2024
428fb07
Add lifecycle as a build reason
natalieparellano May 8, 2024
86c924f
Update cmd/webhook/main.go to add ClusterLifecycleKind to known gener…
natalieparellano May 8, 2024
8e84c40
Add lifecycle to builder spec, builder status, and builder record
natalieparellano May 8, 2024
add47fa
Add TODO
natalieparellano May 8, 2024
0cf19a8
clusterlifecycle tests pass, I guess
natalieparellano May 21, 2024
fda81bf
Passing units for pkg/reconciler/builder/builder_test.go
natalieparellano May 28, 2024
9d0db3a
Add TODO
natalieparellano May 28, 2024
d3cc9d3
Passing units for pkg/reconciler/clusterbuilder/clusterbuilder.go
natalieparellano May 28, 2024
6ba20f8
Add TODO
natalieparellano May 28, 2024
873fd06
Fix pkg/cnb/create_builder_test.go
natalieparellano May 28, 2024
ef9cff5
WIP
natalieparellano May 28, 2024
64d0749
Passing units for pkg/cnb/create_builder.go
natalieparellano May 28, 2024
33518b7
Add TODO
natalieparellano May 28, 2024
ba5a184
Update ResolvedClusterLifecycle struct and rerun codegen
natalieparellano May 29, 2024
ff88c9c
Resolve some TODOs
natalieparellano May 29, 2024
8f39bc4
Validate that lifecycle image arch & arch variant match builder
natalieparellano May 29, 2024
89000bc
Implement remote lifecycle reader
natalieparellano May 29, 2024
d001458
Delete unneeded things
natalieparellano May 29, 2024
b54d5c5
Fix SLSA
natalieparellano May 29, 2024
94736b7
Trigger a new build when the lifecycle changes
natalieparellano May 29, 2024
cd19fbb
Fix controller compile
natalieparellano May 29, 2024
2085772
Trigger updates on a change to the lifecycle commit, not the lifecycl…
natalieparellano Jun 4, 2024
905ea8e
Don't wait for the lifecycle config map informer to be ready,
natalieparellano Jun 6, 2024
5371322
Emit a better error when the lifecycle isn't ready
natalieparellano Jun 6, 2024
c1595ab
Fix reading lifecycle metadata from image labels
natalieparellano Jun 6, 2024
38b4b80
Trigger new builds on new lifecycle version, not commit
natalieparellano Jun 6, 2024
34c7efc
Remove hack/lifecycle
natalieparellano Jun 17, 2024
920682e
Fix reading lifecycle metadata from image labels (and test!)
natalieparellano Jun 17, 2024
cd708ac
Fix e2e tests maybe
natalieparellano Jun 17, 2024
3377b79
Add unit test
natalieparellano Jun 18, 2024
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
154 changes: 154 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -5703,6 +5703,10 @@
},
"kpack.build.v1alpha2.BuildStatus": {
"type": "object",
"required": [
"lifecycleVersion",
"lifecycleCommit"
],
"properties": {
"buildMetadata": {
"type": "array",
Expand All @@ -5721,12 +5725,23 @@
"x-kubernetes-patch-merge-key": "type",
"x-kubernetes-patch-strategy": "merge"
},
"latestAttestationImage": {
"type": "string"
},
"latestCacheImage": {
"type": "string"
},
"latestImage": {
"type": "string"
},
"lifecycleCommit": {
"type": "string",
"default": ""
},
"lifecycleVersion": {
"type": "string",
"default": ""
},
"observedGeneration": {
"description": "ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.",
"type": "integer",
Expand Down Expand Up @@ -5886,6 +5901,10 @@
"default": ""
}
},
"lifecycle": {
"default": {},
"$ref": "#/definitions/io.k8s.api.core.v1.ObjectReference"
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -5930,6 +5949,10 @@
"latestImage": {
"type": "string"
},
"lifecycle": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.ResolvedClusterLifecycle"
},
"observedGeneration": {
"description": "ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.",
"type": "integer",
Expand Down Expand Up @@ -6129,6 +6152,10 @@
"default": ""
}
},
"lifecycle": {
"default": {},
"$ref": "#/definitions/io.k8s.api.core.v1.ObjectReference"
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6250,6 +6277,109 @@
}
}
},
"kpack.build.v1alpha2.ClusterLifecycle": {
"type": "object",
"required": [
"spec",
"status"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
"default": {},
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta"
},
"spec": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.ClusterLifecycleSpec"
},
"status": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.ClusterLifecycleStatus"
}
}
},
"kpack.build.v1alpha2.ClusterLifecycleList": {
"type": "object",
"required": [
"metadata",
"items"
],
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"items": {
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.ClusterLifecycle"
}
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
"default": {},
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
}
}
},
"kpack.build.v1alpha2.ClusterLifecycleSpec": {
"type": "object",
"properties": {
"image": {
"type": "string"
},
"serviceAccountRef": {
"$ref": "#/definitions/io.k8s.api.core.v1.ObjectReference"
}
}
},
"kpack.build.v1alpha2.ClusterLifecycleStatus": {
"type": "object",
"properties": {
"api": {
"description": "Deprecated: Use `LifecycleAPIs` instead",
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.LifecycleAPI"
},
"apis": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.LifecycleAPIs"
},
"commit": {
"type": "string"
},
"conditions": {
"description": "Conditions the latest available observations of a resource's current state.",
"type": "array",
"items": {
"default": {},
"$ref": "#/definitions/kpack.core.v1alpha1.Condition"
},
"x-kubernetes-patch-merge-key": "type",
"x-kubernetes-patch-strategy": "merge"
},
"observedGeneration": {
"description": "ObservedGeneration is the 'Generation' of the Service that was last processed by the controller.",
"type": "integer",
"format": "int64"
},
"version": {
"type": "string"
}
}
},
"kpack.build.v1alpha2.ClusterStack": {
"type": "object",
"required": [
Expand Down Expand Up @@ -6825,6 +6955,10 @@
"default": ""
}
},
"lifecycle": {
"default": {},
"$ref": "#/definitions/io.k8s.api.core.v1.ObjectReference"
},
"order": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6864,6 +6998,26 @@
}
}
},
"kpack.build.v1alpha2.ResolvedClusterLifecycle": {
"type": "object",
"properties": {
"api": {
"description": "Deprecated: Use `LifecycleAPIs` instead",
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.LifecycleAPI"
},
"apis": {
"default": {},
"$ref": "#/definitions/kpack.build.v1alpha2.LifecycleAPIs"
},
"commit": {
"type": "string"
},
"version": {
"type": "string"
}
}
},
"kpack.build.v1alpha2.ResolvedClusterStack": {
"type": "object",
"properties": {
Expand Down
43 changes: 13 additions & 30 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -14,7 +13,6 @@ import (
ociremote "github.com/sigstore/cosign/v2/pkg/oci/remote"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
Expand All @@ -30,7 +28,6 @@ import (
"knative.dev/pkg/metrics"
"knative.dev/pkg/profiling"
"knative.dev/pkg/signals"
"knative.dev/pkg/system"

"github.com/pivotal/kpack/cmd"
_ "github.com/pivotal/kpack/internal/logrus/fatal"
Expand All @@ -52,10 +49,10 @@ import (
"github.com/pivotal/kpack/pkg/reconciler/buildpack"
"github.com/pivotal/kpack/pkg/reconciler/clusterbuilder"
"github.com/pivotal/kpack/pkg/reconciler/clusterbuildpack"
"github.com/pivotal/kpack/pkg/reconciler/clusterlifecycle"
"github.com/pivotal/kpack/pkg/reconciler/clusterstack"
"github.com/pivotal/kpack/pkg/reconciler/clusterstore"
"github.com/pivotal/kpack/pkg/reconciler/image"
"github.com/pivotal/kpack/pkg/reconciler/lifecycle"
"github.com/pivotal/kpack/pkg/reconciler/sourceresolver"
"github.com/pivotal/kpack/pkg/registry"
"github.com/pivotal/kpack/pkg/secret"
Expand Down Expand Up @@ -133,6 +130,7 @@ func main() {
buildpackInformer := informerFactory.Kpack().V1alpha2().Buildpacks()
clusterBuilderInformer := informerFactory.Kpack().V1alpha2().ClusterBuilders()
clusterBuildpackInformer := informerFactory.Kpack().V1alpha2().ClusterBuildpacks()
clusterLifecycleInformer := informerFactory.Kpack().V1alpha2().ClusterLifecycles()
clusterStoreInformer := informerFactory.Kpack().V1alpha2().ClusterStores()
clusterStackInformer := informerFactory.Kpack().V1alpha2().ClusterStacks()

Expand All @@ -148,15 +146,6 @@ func main() {
if err != nil {
log.Fatalf("could not create k8s keychain factory: %s", err)
}
lifecycleConfigmapInformerFactory := informers.NewSharedInformerFactoryWithOptions(
k8sClient,
options.ResyncPeriod,
informers.WithNamespace(system.Namespace()),
informers.WithTweakListOptions(func(options *metav1.ListOptions) {
options.FieldSelector = fmt.Sprintf("metadata.namespace=%s,metadata.name=%s", system.Namespace(), config.LifecycleConfigName)
}),
)
lifecycleConfigmapInformer := lifecycleConfigmapInformerFactory.Core().V1().ConfigMaps()

metadataRetriever := &cnb.RemoteMetadataRetriever{
ImageFetcher: &registry.Client{},
Expand Down Expand Up @@ -195,14 +184,14 @@ func main() {
RegistryClient: &registry.Client{},
}

lifecycleProvider := config.NewLifecycleProvider(&registry.Client{}, keychainFactory)
remoteLifecycleReader := &cnb.RemoteLifecycleReader{
RegistryClient: &registry.Client{},
}

builderCreator := &cnb.RemoteBuilderCreator{
RegistryClient: &registry.Client{},
KpackVersion: cmd.Identifer,
LifecycleProvider: lifecycleProvider,
KeychainFactory: keychainFactory,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated change, this seems no longer used

ImageSigner: cosign.NewImageSigner(sign.SignCmd, ociremote.SignatureTag),
RegistryClient: &registry.Client{},
KpackVersion: cmd.Identifer,
ImageSigner: cosign.NewImageSigner(sign.SignCmd, ociremote.SignatureTag),
}

podProgressLogger := &buildchange.ProgressLogger{
Expand All @@ -212,8 +201,7 @@ func main() {
slsaAttester := slsa.Attester{
Version: cmd.Version,

LifecycleProvider: lifecycleProvider,
ImageReader: slsa.NewImageReader(&registry.Client{}),
ImageReader: slsa.NewImageReader(&registry.Client{}),

Images: images,
Features: featureFlags,
Expand All @@ -229,29 +217,24 @@ func main() {
buildController := build.NewController(ctx, options, k8sClient, buildInformer, podInformer, metadataRetriever, buildpodGenerator, podProgressLogger, keychainFactory, &slsaAttester, secretFetcher, featureFlags)
imageController := image.NewController(ctx, options, k8sClient, imageInformer, buildInformer, duckBuilderInformer, sourceResolverInformer, pvcInformer, cfg.EnablePriorityClasses)
sourceResolverController := sourceresolver.NewController(ctx, options, sourceResolverInformer, gitResolver, blobResolver, registryResolver)
builderController, builderResync := builder.NewController(ctx, options, builderInformer, builderCreator, keychainFactory, clusterStoreInformer, buildpackInformer, clusterBuildpackInformer, clusterStackInformer, secretFetcher)
builderController := builder.NewController(ctx, options, builderInformer, builderCreator, keychainFactory, clusterStoreInformer, buildpackInformer, clusterBuildpackInformer, clusterStackInformer, clusterLifecycleInformer, secretFetcher)
buildpackController := buildpack.NewController(ctx, options, keychainFactory, buildpackInformer, remoteStoreReader)
clusterBuilderController, clusterBuilderResync := clusterbuilder.NewController(ctx, options, clusterBuilderInformer, builderCreator, keychainFactory, clusterStoreInformer, clusterBuildpackInformer, clusterStackInformer, secretFetcher)
clusterBuilderController := clusterbuilder.NewController(ctx, options, clusterBuilderInformer, builderCreator, keychainFactory, clusterStoreInformer, clusterBuildpackInformer, clusterStackInformer, clusterLifecycleInformer, secretFetcher)
clusterBuildpackController := clusterbuildpack.NewController(ctx, options, keychainFactory, clusterBuildpackInformer, remoteStoreReader)
clusterStoreController := clusterstore.NewController(ctx, options, keychainFactory, clusterStoreInformer, remoteStoreReader)
clusterStackController := clusterstack.NewController(ctx, options, keychainFactory, clusterStackInformer, remoteStackReader)
lifecycleController := lifecycle.NewController(ctx, options, k8sClient, config.LifecycleConfigName, lifecycleConfigmapInformer, lifecycleProvider)

lifecycleProvider.AddEventHandler(builderResync)
lifecycleProvider.AddEventHandler(clusterBuilderResync)
clusterLifecycleController := clusterlifecycle.NewController(ctx, options, keychainFactory, clusterLifecycleInformer, remoteLifecycleReader)

stopChan := make(chan struct{})
informerFactory.Start(stopChan)
k8sInformerFactory.Start(stopChan)
lifecycleConfigmapInformerFactory.Start(stopChan)

waitForSync(stopChan,
buildInformer.Informer(),
imageInformer.Informer(),
sourceResolverInformer.Informer(),
pvcInformer.Informer(),
podInformer.Informer(),
lifecycleConfigmapInformer.Informer(),
builderInformer.Informer(),
buildpackInformer.Informer(),
clusterBuilderInformer.Informer(),
Expand All @@ -263,14 +246,14 @@ func main() {
err = runGroup(
ctx,
run(clusterStackController, routinesPerController),
run(clusterLifecycleController, routinesPerController),
run(imageController, routinesPerController),
run(buildController, routinesPerController),
run(builderController, routinesPerController),
run(buildpackController, routinesPerController),
run(clusterBuilderController, routinesPerController),
run(clusterBuildpackController, routinesPerController),
run(clusterStoreController, routinesPerController),
run(lifecycleController, routinesPerController),
run(sourceResolverController, 2*routinesPerController),
func(ctx context.Context) error {
return configMapWatcher.Start(ctx.Done())
Expand Down
1 change: 1 addition & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.ClusterBuildpackKind): &v1alpha2.ClusterBuildpack{},
v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.ClusterStoreKind): &v1alpha2.ClusterStore{},
v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.ClusterStackKind): &v1alpha2.ClusterStack{},
v1alpha2.SchemeGroupVersion.WithKind(v1alpha2.ClusterLifecycleKind): &v1alpha2.ClusterLifecycle{},
}

func init() {
Expand Down
Loading
Loading