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

Rollouts package discovery #3697

Merged
Merged
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
35 changes: 31 additions & 4 deletions rollouts/api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,47 @@ type RolloutSpec struct {
// Description is a user friendly description of this Rollout.
Description string `json:"description,omitempty"`

// Packages source for this Rollout.
Packages PackagesConfig `json:"packages"`

// Targets specifies the clusters that will receive the KRM config packages.
Targets ClusterTargetSelector `json:"targets,omitempty"`

// PackageSourceType identifies how the KRM config unit will be sourced.
PackageSourceType PackageSourceType `json:"packageSourceType,omitempty"`
}

type ClusterTargetSelector struct {
Selector *metav1.LabelSelector `json:"selector,omitempty"`
}

// +kubebuilder:validation:Enum=gitRepo;gitDir
// +kubebuilder:validation:Enum=git
type PackageSourceType string

// PackagesConfig defines the packages the Rollout should deploy.
type PackagesConfig struct {
SourceType PackageSourceType `json:"sourceType"`

Git GitSource `json:"git"`
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make this a pointer since this will be an optional field.

}

// GitSource defines the packages source in Git.
type GitSource struct {
GitRepoSelector GitSelector `json:"selector"`
}

// GitSelector defines the selector to apply to Git.
type GitSelector struct {
Org string `json:"org"`
Name string `json:"name"`
Directory string `json:"directory"`
Revision string `json:"revision"`
SecretRef SecretReference `json:"secretRef,omitempty"`
}

// SecretReference contains the reference to the secret
type SecretReference struct {
// Name represents the secret name
Name string `json:"name,omitempty"`
}

// RolloutStatus defines the observed state of Rollout
type RolloutStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
64 changes: 64 additions & 0 deletions rollouts/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions rollouts/config/crd/bases/gitops.kpt.dev_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,49 @@ spec:
description:
description: Description is a user friendly description of this Rollout.
type: string
packageSourceType:
description: PackageSourceType identifies how the KRM config unit
will be sourced.
enum:
- gitRepo
- gitDir
type: string
packages:
description: Packages source for this Rollout.
properties:
git:
description: GitSource defines the packages source in Git.
properties:
selector:
description: GitSelector defines the selector to apply to
Git.
properties:
directory:
type: string
name:
type: string
org:
type: string
revision:
type: string
secretRef:
description: SecretReference contains the reference to
the secret
properties:
name:
description: Name represents the secret name
type: string
type: object
required:
- directory
- name
- org
- revision
type: object
required:
- selector
type: object
sourceType:
enum:
- git
type: string
required:
- git
- sourceType
type: object
targets:
description: Targets specifies the clusters that will receive the
KRM config packages.
Expand Down Expand Up @@ -98,6 +134,8 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: object
required:
- packages
type: object
status:
description: RolloutStatus defines the observed state of Rollout
Expand Down
9 changes: 8 additions & 1 deletion rollouts/config/samples/gitops_v1alpha1_rollout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ metadata:
app.kubernetes.io/created-by: rollouts
name: rollout-sample
spec:
packageSourceType: gitRepo
description: "this is first rollout :)"
packages:
sourceType: git
git:
selector:
org: GoogleContainerTools
name: kpt-samples
directory: "*"
revision: main
targets:
selector:
matchExpressions:
Expand Down
20 changes: 20 additions & 0 deletions rollouts/controllers/rollout_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
gkeclusterapis "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/container/v1beta1"
gitopsv1alpha1 "github.com/GoogleContainerTools/kpt/rollouts/api/v1alpha1"
"github.com/GoogleContainerTools/kpt/rollouts/pkg/clusterstore"
"github.com/GoogleContainerTools/kpt/rollouts/pkg/packagediscovery"
)

var (
Expand Down Expand Up @@ -111,6 +112,25 @@ func (r *RolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
r.testClusterClient(ctx, cl)
}

if err := r.Get(ctx, req.NamespacedName, &rollout); err != nil {
logger.Error(err, "unable to fetch Rollout")
// we'll ignore not-found errors, since they can't be fixed by an immediate
// requeue (we'll need to wait for a new notification), and we can get them
// on deleted requests.
return ctrl.Result{}, client.IgnoreNotFound(err)
}

packageDiscoveryClient := packagediscovery.NewPackageDiscovery(rollout.Spec.Packages, r.Client, req.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not urgent, but we will have to figure out mechanism for caching these discovered packages.


discoveredPackages, err := packageDiscoveryClient.GetPackages(ctx)
if err != nil {
logger.Error(err, "package discovery failed")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

logger.Info("discovered packages", "count", len(discoveredPackages), "packages", discoveredPackages)

return ctrl.Result{}, err
}

Expand Down
2 changes: 2 additions & 0 deletions rollouts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
cloud.google.com/go/iam v0.7.0
github.com/GoogleCloudPlatform/k8s-config-connector v1.98.0
github.com/golang/protobuf v1.5.2
github.com/google/go-github/v48 v48.2.0
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.1
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
Expand Down Expand Up @@ -43,6 +44,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions rollouts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,16 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v48 v48.2.0 h1:68puzySE6WqUY9KWmpOsDEQfDZsso98rT6pZcz9HqcE=
github.com/google/go-github/v48 v48.2.0/go.mod h1:dDlehKBDo850ZPvCTK0sEqTCVWcrGl2LcDiajkYi89Y=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
Loading