Skip to content

Commit

Permalink
create DownstreamPackage controller (#3684)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Dec 8, 2022
1 parent 8e9f29e commit 3657aec
Show file tree
Hide file tree
Showing 10 changed files with 820 additions and 1 deletion.
2 changes: 1 addition & 1 deletion porch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_GIT_SERVER_IMAGE ?= test-git-server
# Only enable a subset of reconcilers in porch controllers by default. Use the RECONCILERS
# env variable to specify a specific list of reconcilers or use
# RECONCILERS=* to enable all known reconcilers.
ALL_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,rootsyncdeployments,functiondiscovery"
ALL_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,rootsyncdeployments,functiondiscovery,downstreampackages"
ifndef RECONCILERS
ENABLED_RECONCILERS="rootsyncsets,remoterootsyncsets,workloadidentitybindings,functiondiscovery"
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.8.0
creationTimestamp: null
name: downstreampackages.config.porch.kpt.dev
spec:
group: config.porch.kpt.dev
names:
kind: DownstreamPackage
listKind: DownstreamPackageList
plural: downstreampackages
singular: downstreampackage
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: DownstreamPackage represents an upstream and downstream porch
package pair. The upstream package should already exist. The DownstreamPackage
controller is responsible for creating the downstream package revisions
based on the spec.
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:
type: object
spec:
description: DownstreamPackageSpec defines the desired state of DownstreamPackage
properties:
adoptionPolicy:
type: string
deletionPolicy:
type: string
downstream:
properties:
package:
type: string
repo:
type: string
type: object
upstream:
properties:
package:
type: string
repo:
type: string
revision:
type: string
type: object
type: object
status:
description: DownstreamPackageStatus defines the observed state of DownstreamPackage
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// DownstreamPackage represents an upstream and downstream porch package pair.
// The upstream package should already exist. The DownstreamPackage controller is
// responsible for creating the downstream package revisions based on the spec.
type DownstreamPackage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DownstreamPackageSpec `json:"spec,omitempty"`
Status DownstreamPackageStatus `json:"status,omitempty"`
}

func (o *DownstreamPackage) GetSpec() *DownstreamPackageSpec {
if o == nil {
return nil
}
return &o.Spec
}

type AdoptionPolicy string
type DeletionPolicy string

const (
AdoptionPolicyAdoptExisting AdoptionPolicy = "adoptExisting"
AdoptionPolicyAdoptNone AdoptionPolicy = "adoptNone"

DeletionPolicyDelete DeletionPolicy = "delete"
DeletionPolicyOrphan DeletionPolicy = "orphan"
)

// DownstreamPackageSpec defines the desired state of DownstreamPackage
type DownstreamPackageSpec struct {
Upstream *Upstream `json:"upstream,omitempty"`
Downstream *Downstream `json:"downstream,omitempty"`

AdoptionPolicy AdoptionPolicy `json:"adoptionPolicy,omitempty"`
DeletionPolicy DeletionPolicy `json:"deletionPolicy,omitempty"`
}

type Upstream struct {
Repo string `json:"repo,omitempty"`
Package string `json:"package,omitempty"`
Revision string `json:"revision,omitempty"`
}

type Downstream struct {
Repo string `json:"repo,omitempty"`
Package string `json:"package,omitempty"`
}

// DownstreamPackageStatus defines the observed state of DownstreamPackage
type DownstreamPackageStatus struct{}

//+kubebuilder:object:root=true

// DownstreamPackageList contains a list of DownstreamPackage
type DownstreamPackageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DownstreamPackage `json:"items"`
}

func init() {
SchemeBuilder.Register(&DownstreamPackage{}, &DownstreamPackageList{})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package v1alpha1 contains API Schema definitions for the config.porch.kpt.dev v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=config.porch.kpt.dev
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 object object:headerFile="../../../../scripts/boilerplate.go.txt" paths="./..."

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "config.porch.kpt.dev", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)

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

0 comments on commit 3657aec

Please sign in to comment.