commit
22bbab7fe4
|
@ -42,14 +42,14 @@ jobs:
|
||||||
- name: Run smoke tests
|
- name: Run smoke tests
|
||||||
run: |
|
run: |
|
||||||
kubectl apply -f ./config/samples
|
kubectl apply -f ./config/samples
|
||||||
kubectl -n sourcer-system rollout status deploy/sourcer-controller --timeout=1m
|
kubectl -n source-system rollout status deploy/source-controller --timeout=1m
|
||||||
kubectl wait gitrepository/podinfo --for=condition=ready --timeout=1m
|
kubectl wait gitrepository/podinfo --for=condition=ready --timeout=1m
|
||||||
kubectl wait helmrepository/podinfo --for=condition=ready --timeout=1m
|
kubectl wait helmrepository/podinfo --for=condition=ready --timeout=1m
|
||||||
kubectl -n sourcer-system logs deploy/sourcer-controller
|
kubectl -n source-system logs deploy/source-controller
|
||||||
- name: Debug failure
|
- name: Debug failure
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
kubectl get gitrepositories -oyaml
|
kubectl get gitrepositories -oyaml
|
||||||
kubectl get helmrepositories -oyaml
|
kubectl get helmrepositories -oyaml
|
||||||
kubectl -n sourcer-system get all
|
kubectl -n source-system get all
|
||||||
kubectl -n sourcer-system logs deploy/sourcer-controller
|
kubectl -n source-system logs deploy/source-controller
|
||||||
|
|
|
@ -15,12 +15,12 @@ COPY api/ api/
|
||||||
COPY controllers/ controllers/
|
COPY controllers/ controllers/
|
||||||
|
|
||||||
# build
|
# build
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o sourcer main.go
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o source-controller main.go
|
||||||
|
|
||||||
FROM alpine:3.11
|
FROM alpine:3.11
|
||||||
|
|
||||||
RUN apk add --no-cache openssh-client ca-certificates tini 'git>=2.12.0' socat curl bash
|
RUN apk add --no-cache openssh-client ca-certificates tini 'git>=2.12.0' socat curl bash
|
||||||
|
|
||||||
COPY --from=builder /workspace/sourcer /usr/local/bin/
|
COPY --from=builder /workspace/source-controller /usr/local/bin/
|
||||||
|
|
||||||
ENTRYPOINT [ "/sbin/tini", "--", "sourcer" ]
|
ENTRYPOINT [ "/sbin/tini", "--", "source-controller" ]
|
||||||
|
|
6
Makefile
6
Makefile
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
# Image URL to use all building/pushing image targets
|
# Image URL to use all building/pushing image targets
|
||||||
IMG ?= fluxcd/sourcer:latest
|
IMG ?= fluxcd/source-controller:latest
|
||||||
# Produce CRDs that work back to Kubernetes 1.13
|
# Produce CRDs that work back to Kubernetes 1.13
|
||||||
CRD_OPTIONS ?= crd
|
CRD_OPTIONS ?= crd
|
||||||
|
|
||||||
|
@ -35,13 +35,13 @@ uninstall: manifests
|
||||||
|
|
||||||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
|
||||||
deploy: manifests
|
deploy: manifests
|
||||||
cd config/manager && kustomize edit set image fluxcd/sourcer=${IMG}
|
cd config/manager && kustomize edit set image fluxcd/source-controller=${IMG}
|
||||||
kustomize build config/default | kubectl apply -f -
|
kustomize build config/default | kubectl apply -f -
|
||||||
|
|
||||||
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
|
# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
|
||||||
dev-deploy: manifests
|
dev-deploy: manifests
|
||||||
mkdir -p config/dev && cp config/default/* config/dev
|
mkdir -p config/dev && cp config/default/* config/dev
|
||||||
cd config/dev && kustomize edit set image fluxcd/sourcer=${IMG}
|
cd config/dev && kustomize edit set image fluxcd/source-controller=${IMG}
|
||||||
kustomize build config/dev | kubectl apply -f -
|
kustomize build config/dev | kubectl apply -f -
|
||||||
rm -rf config/dev
|
rm -rf config/dev
|
||||||
|
|
||||||
|
|
6
PROJECT
6
PROJECT
|
@ -1,10 +1,10 @@
|
||||||
domain: fluxcd.io
|
domain: fluxcd.io
|
||||||
repo: github.com/fluxcd/sourcer
|
repo: github.com/fluxcd/source-controller
|
||||||
resources:
|
resources:
|
||||||
- group: sourcer
|
- group: source
|
||||||
kind: GitRepository
|
kind: GitRepository
|
||||||
version: v1alpha1
|
version: v1alpha1
|
||||||
- group: sourcer
|
- group: source
|
||||||
kind: HelmRepository
|
kind: HelmRepository
|
||||||
version: v1alpha1
|
version: v1alpha1
|
||||||
version: "2"
|
version: "2"
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
# sourcer
|
# Source controller
|
||||||
Experimental source manager
|
|
||||||
|
Experimental source manager and artifact provider.
|
||||||
|
|
|
@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package v1alpha1 contains API Schema definitions for the sourcer v1alpha1 API group
|
// Package v1alpha1 contains API Schema definitions for the source v1alpha1 API group
|
||||||
// +kubebuilder:object:generate=true
|
// +kubebuilder:object:generate=true
|
||||||
// +groupName=sourcer.fluxcd.io
|
// +groupName=source.fluxcd.io
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -26,7 +26,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// GroupVersion is group version used to register these objects
|
// GroupVersion is group version used to register these objects
|
||||||
GroupVersion = schema.GroupVersion{Group: "sourcer.fluxcd.io", Version: "v1alpha1"}
|
GroupVersion = schema.GroupVersion{Group: "source.fluxcd.io", Version: "v1alpha1"}
|
||||||
|
|
||||||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
|
||||||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
|
||||||
|
|
|
@ -6,7 +6,7 @@ metadata:
|
||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.2.5
|
controller-gen.kubebuilder.io/version: v0.2.5
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: gitrepositories.sourcer.fluxcd.io
|
name: gitrepositories.source.fluxcd.io
|
||||||
spec:
|
spec:
|
||||||
additionalPrinterColumns:
|
additionalPrinterColumns:
|
||||||
- JSONPath: .spec.url
|
- JSONPath: .spec.url
|
||||||
|
@ -21,7 +21,7 @@ spec:
|
||||||
- JSONPath: .metadata.creationTimestamp
|
- JSONPath: .metadata.creationTimestamp
|
||||||
name: Age
|
name: Age
|
||||||
type: date
|
type: date
|
||||||
group: sourcer.fluxcd.io
|
group: source.fluxcd.io
|
||||||
names:
|
names:
|
||||||
kind: GitRepository
|
kind: GitRepository
|
||||||
listKind: GitRepositoryList
|
listKind: GitRepositoryList
|
|
@ -6,7 +6,7 @@ metadata:
|
||||||
annotations:
|
annotations:
|
||||||
controller-gen.kubebuilder.io/version: v0.2.5
|
controller-gen.kubebuilder.io/version: v0.2.5
|
||||||
creationTimestamp: null
|
creationTimestamp: null
|
||||||
name: helmrepositories.sourcer.fluxcd.io
|
name: helmrepositories.source.fluxcd.io
|
||||||
spec:
|
spec:
|
||||||
additionalPrinterColumns:
|
additionalPrinterColumns:
|
||||||
- JSONPath: .spec.url
|
- JSONPath: .spec.url
|
||||||
|
@ -21,7 +21,7 @@ spec:
|
||||||
- JSONPath: .metadata.creationTimestamp
|
- JSONPath: .metadata.creationTimestamp
|
||||||
name: Age
|
name: Age
|
||||||
type: date
|
type: date
|
||||||
group: sourcer.fluxcd.io
|
group: source.fluxcd.io
|
||||||
names:
|
names:
|
||||||
kind: HelmRepository
|
kind: HelmRepository
|
||||||
listKind: HelmRepositoryList
|
listKind: HelmRepositoryList
|
|
@ -1,7 +1,7 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
resources:
|
resources:
|
||||||
- bases/sourcer.fluxcd.io_gitrepositories.yaml
|
- bases/source.fluxcd.io_gitrepositories.yaml
|
||||||
- bases/sourcer.fluxcd.io_helmrepositories.yaml
|
- bases/source.fluxcd.io_helmrepositories.yaml
|
||||||
# +kubebuilder:scaffold:crdkustomizeresource
|
# +kubebuilder:scaffold:crdkustomizeresource
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: sourcer-system
|
namespace: source-system
|
||||||
namePrefix: sourcer-
|
namePrefix: source-
|
||||||
bases:
|
bases:
|
||||||
- ../crd
|
- ../crd
|
||||||
- ../rbac
|
- ../rbac
|
||||||
|
|
|
@ -8,12 +8,12 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: sourcer
|
app: source-controller
|
||||||
replicas: 1
|
replicas: 1
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: sourcer
|
app: source-controller
|
||||||
annotations:
|
annotations:
|
||||||
prometheus.io/scrape: "true"
|
prometheus.io/scrape: "true"
|
||||||
prometheus.io/port: "9090"
|
prometheus.io/port: "9090"
|
||||||
|
@ -21,7 +21,7 @@ spec:
|
||||||
terminationGracePeriodSeconds: 10
|
terminationGracePeriodSeconds: 10
|
||||||
containers:
|
containers:
|
||||||
- name: manager
|
- name: manager
|
||||||
image: fluxcd/sourcer
|
image: fluxcd/source-controller
|
||||||
imagePullPolicy: IfNotPresent
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
|
|
|
@ -5,5 +5,5 @@ resources:
|
||||||
- service.yaml
|
- service.yaml
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
images:
|
images:
|
||||||
- name: fluxcd/sourcer
|
- name: fluxcd/source-controller
|
||||||
newTag: 0.0.1-alpha.1
|
newTag: 0.0.1-alpha.1
|
||||||
|
|
|
@ -8,7 +8,7 @@ metadata:
|
||||||
spec:
|
spec:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
selector:
|
selector:
|
||||||
app: sourcer
|
app: source-controller
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
port: 80
|
port: 80
|
||||||
|
|
|
@ -5,7 +5,7 @@ metadata:
|
||||||
name: gitrepository-editor-role
|
name: gitrepository-editor-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories
|
- gitrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -17,7 +17,7 @@ rules:
|
||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories/status
|
- gitrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|
|
@ -5,7 +5,7 @@ metadata:
|
||||||
name: gitrepository-viewer-role
|
name: gitrepository-viewer-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories
|
- gitrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -13,7 +13,7 @@ rules:
|
||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories/status
|
- gitrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|
|
@ -5,7 +5,7 @@ metadata:
|
||||||
name: helmrepository-editor-role
|
name: helmrepository-editor-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories
|
- helmrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -17,7 +17,7 @@ rules:
|
||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories/status
|
- helmrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|
|
@ -5,7 +5,7 @@ metadata:
|
||||||
name: helmrepository-viewer-role
|
name: helmrepository-viewer-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories
|
- helmrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -13,7 +13,7 @@ rules:
|
||||||
- list
|
- list
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories/status
|
- helmrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|
|
@ -7,7 +7,7 @@ metadata:
|
||||||
name: manager-role
|
name: manager-role
|
||||||
rules:
|
rules:
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories
|
- gitrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -19,7 +19,7 @@ rules:
|
||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- gitrepositories/status
|
- gitrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -27,7 +27,7 @@ rules:
|
||||||
- patch
|
- patch
|
||||||
- update
|
- update
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories
|
- helmrepositories
|
||||||
verbs:
|
verbs:
|
||||||
|
@ -39,7 +39,7 @@ rules:
|
||||||
- update
|
- update
|
||||||
- watch
|
- watch
|
||||||
- apiGroups:
|
- apiGroups:
|
||||||
- sourcer.fluxcd.io
|
- source.fluxcd.io
|
||||||
resources:
|
resources:
|
||||||
- helmrepositories/status
|
- helmrepositories/status
|
||||||
verbs:
|
verbs:
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
apiVersion: sourcer.fluxcd.io/v1alpha1
|
apiVersion: source.fluxcd.io/v1alpha1
|
||||||
kind: GitRepository
|
kind: GitRepository
|
||||||
metadata:
|
metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
annotations:
|
annotations:
|
||||||
sourcer.fluxcd.io/syncAt: "2020-04-06T15:39:52+03:00"
|
source.fluxcd.io/syncAt: "2020-04-06T15:39:52+03:00"
|
||||||
spec:
|
spec:
|
||||||
interval: 1m
|
interval: 1m
|
||||||
url: https://github.com/stefanprodan/podinfo
|
url: https://github.com/stefanprodan/podinfo
|
|
@ -1,8 +1,7 @@
|
||||||
apiVersion: sourcer.fluxcd.io/v1alpha1
|
apiVersion: source.fluxcd.io/v1alpha1
|
||||||
kind: HelmRepository
|
kind: HelmRepository
|
||||||
metadata:
|
metadata:
|
||||||
name: podinfo
|
name: podinfo
|
||||||
spec:
|
spec:
|
||||||
interval: 1m
|
interval: 1m
|
||||||
url: https://stefanprodan.github.io/podinfo
|
url: https://stefanprodan.github.io/podinfo
|
||||||
|
|
|
@ -38,7 +38,7 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/event"
|
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||||
|
|
||||||
sourcerv1 "github.com/fluxcd/sourcer/api/v1alpha1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GitRepositoryReconciler reconciles a GitRepository object
|
// GitRepositoryReconciler reconciles a GitRepository object
|
||||||
|
@ -49,8 +49,8 @@ type GitRepositoryReconciler struct {
|
||||||
StoragePath string
|
StoragePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=sourcer.fluxcd.io,resources=gitrepositories,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=gitrepositories,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=sourcer.fluxcd.io,resources=gitrepositories/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=gitrepositories/status,verbs=get;update;patch
|
||||||
|
|
||||||
func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
@ -58,7 +58,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||||
|
|
||||||
log := r.Log.WithValues("gitrepository", req.NamespacedName)
|
log := r.Log.WithValues("gitrepository", req.NamespacedName)
|
||||||
|
|
||||||
var repo sourcerv1.GitRepository
|
var repo sourcev1.GitRepository
|
||||||
if err := r.Get(ctx, req.NamespacedName, &repo); err != nil {
|
if err := r.Get(ctx, req.NamespacedName, &repo); err != nil {
|
||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
}
|
}
|
||||||
|
@ -70,9 +70,9 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||||
log.Info("Initialising repository")
|
log.Info("Initialising repository")
|
||||||
repo.Status.Artifacts = ""
|
repo.Status.Artifacts = ""
|
||||||
repo.Status.LastUpdateTime = nil
|
repo.Status.LastUpdateTime = nil
|
||||||
repo.Status.Conditions = []sourcerv1.RepositoryCondition{
|
repo.Status.Conditions = []sourcev1.RepositoryCondition{
|
||||||
{
|
{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionUnknown,
|
Status: corev1.ConditionUnknown,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||||
// update status
|
// update status
|
||||||
timeNew := metav1.Now()
|
timeNew := metav1.Now()
|
||||||
readyCondition.LastTransitionTime = &timeNew
|
readyCondition.LastTransitionTime = &timeNew
|
||||||
repo.Status.Conditions = []sourcerv1.RepositoryCondition{readyCondition}
|
repo.Status.Conditions = []sourcev1.RepositoryCondition{readyCondition}
|
||||||
|
|
||||||
if err := r.Status().Update(ctx, &repo); err != nil {
|
if err := r.Status().Update(ctx, &repo); err != nil {
|
||||||
log.Error(err, "unable to update GitRepository status")
|
log.Error(err, "unable to update GitRepository status")
|
||||||
|
@ -112,7 +112,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
|
||||||
|
|
||||||
func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&sourcerv1.GitRepository{}).
|
For(&sourcev1.GitRepository{}).
|
||||||
WithEventFilter(RepositoryChangePredicate{}).
|
WithEventFilter(RepositoryChangePredicate{}).
|
||||||
WithEventFilter(predicate.Funcs{
|
WithEventFilter(predicate.Funcs{
|
||||||
DeleteFunc: func(e event.DeleteEvent) bool {
|
DeleteFunc: func(e event.DeleteEvent) bool {
|
||||||
|
@ -132,7 +132,7 @@ func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
Complete(r)
|
Complete(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.RepositoryCondition, string, error) {
|
func (r *GitRepositoryReconciler) sync(gr sourcev1.GitRepository) (sourcev1.RepositoryCondition, string, error) {
|
||||||
// determine ref
|
// determine ref
|
||||||
refName := plumbing.NewBranchReferenceName("master")
|
refName := plumbing.NewBranchReferenceName("master")
|
||||||
if gr.Spec.Branch != "" {
|
if gr.Spec.Branch != "" {
|
||||||
|
@ -146,8 +146,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
dir, err := ioutil.TempDir("", gr.Name)
|
dir, err := ioutil.TempDir("", gr.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("tmp dir error %w", err)
|
ex := fmt.Errorf("tmp dir error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "ExecFailed",
|
Reason: "ExecFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -165,8 +165,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("git clone error %w", err)
|
ex := fmt.Errorf("git clone error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCloneFailed",
|
Reason: "GitCloneFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -178,8 +178,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
rng, err := semver.ParseRange(gr.Spec.SemVer)
|
rng, err := semver.ParseRange(gr.Spec.SemVer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("semver parse range error %w", err)
|
ex := fmt.Errorf("semver parse range error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCloneFailed",
|
Reason: "GitCloneFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -189,8 +189,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
repoTags, err := repo.Tags()
|
repoTags, err := repo.Tags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("git list tags error %w", err)
|
ex := fmt.Errorf("git list tags error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCloneFailed",
|
Reason: "GitCloneFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -222,8 +222,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
w, err := repo.Worktree()
|
w, err := repo.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("git worktree error %w", err)
|
ex := fmt.Errorf("git worktree error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCheckoutFailed",
|
Reason: "GitCheckoutFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -235,8 +235,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("git checkout error %w", err)
|
ex := fmt.Errorf("git checkout error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCheckoutFailed",
|
Reason: "GitCheckoutFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -244,8 +244,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ex := fmt.Errorf("no match found for semver %s", gr.Spec.SemVer)
|
ex := fmt.Errorf("no match found for semver %s", gr.Spec.SemVer)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitCheckoutFailed",
|
Reason: "GitCheckoutFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -257,8 +257,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
ref, err := repo.Head()
|
ref, err := repo.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("git resolve HEAD error %w", err)
|
ex := fmt.Errorf("git resolve HEAD error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "GitHeadFailed",
|
Reason: "GitHeadFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -271,8 +271,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
err = os.MkdirAll(storage, 0777)
|
err = os.MkdirAll(storage, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("mkdir dir error %w", err)
|
ex := fmt.Errorf("mkdir dir error %w", err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "ExecFailed",
|
Reason: "ExecFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -287,8 +287,8 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
err = command.Run()
|
err = command.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ex := fmt.Errorf("tar %s error %w", artifacts, err)
|
ex := fmt.Errorf("tar %s error %w", artifacts, err)
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionFalse,
|
Status: corev1.ConditionFalse,
|
||||||
Reason: "ExecFailed",
|
Reason: "ExecFailed",
|
||||||
Message: ex.Error(),
|
Message: ex.Error(),
|
||||||
|
@ -305,15 +305,15 @@ func (r *GitRepositoryReconciler) sync(gr sourcerv1.GitRepository) (sourcerv1.Re
|
||||||
artifactsURL := fmt.Sprintf("http://%s/repositories/%s-%s/%s.tar.gz",
|
artifactsURL := fmt.Sprintf("http://%s/repositories/%s-%s/%s.tar.gz",
|
||||||
hostname, gr.Name, gr.Namespace, ref.Hash().String())
|
hostname, gr.Name, gr.Namespace, ref.Hash().String())
|
||||||
|
|
||||||
return sourcerv1.RepositoryCondition{
|
return sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionTrue,
|
Status: corev1.ConditionTrue,
|
||||||
Reason: "GitCloneSucceed",
|
Reason: "GitCloneSucceed",
|
||||||
Message: fmt.Sprintf("Fetched artifacts are available at %s", artifacts),
|
Message: fmt.Sprintf("Fetched artifacts are available at %s", artifacts),
|
||||||
}, artifactsURL, nil
|
}, artifactsURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *GitRepositoryReconciler) shouldResetStatus(gr sourcerv1.GitRepository) bool {
|
func (r *GitRepositoryReconciler) shouldResetStatus(gr sourcev1.GitRepository) bool {
|
||||||
resetStatus := false
|
resetStatus := false
|
||||||
if gr.Status.Artifacts != "" {
|
if gr.Status.Artifacts != "" {
|
||||||
pathParts := strings.Split(gr.Status.Artifacts, "/")
|
pathParts := strings.Split(gr.Status.Artifacts, "/")
|
||||||
|
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sourcerv1 "github.com/fluxcd/sourcer/api/v1alpha1"
|
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
@ -33,6 +32,8 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HelmRepositoryReconciler reconciles a HelmRepository object
|
// HelmRepositoryReconciler reconciles a HelmRepository object
|
||||||
|
@ -42,8 +43,8 @@ type HelmRepositoryReconciler struct {
|
||||||
Scheme *runtime.Scheme
|
Scheme *runtime.Scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:rbac:groups=sourcer.fluxcd.io,resources=helmrepositories,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=helmrepositories,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=sourcer.fluxcd.io,resources=helmrepositories/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=source.fluxcd.io,resources=helmrepositories/status,verbs=get;update;patch
|
||||||
|
|
||||||
func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||||
|
@ -51,27 +52,27 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||||
|
|
||||||
log := r.Log.WithValues("helmrepository", req.NamespacedName)
|
log := r.Log.WithValues("helmrepository", req.NamespacedName)
|
||||||
|
|
||||||
var repo sourcerv1.HelmRepository
|
var repo sourcev1.HelmRepository
|
||||||
|
|
||||||
if err := r.Get(ctx, req.NamespacedName, &repo); err != nil {
|
if err := r.Get(ctx, req.NamespacedName, &repo); err != nil {
|
||||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
readyCondition := sourcerv1.RepositoryCondition{
|
readyCondition := sourcev1.RepositoryCondition{
|
||||||
Type: sourcerv1.RepositoryConditionReady,
|
Type: sourcev1.RepositoryConditionReady,
|
||||||
Status: corev1.ConditionUnknown,
|
Status: corev1.ConditionUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(repo.Status.Conditions) == 0 {
|
if len(repo.Status.Conditions) == 0 {
|
||||||
log.Info("Starting index download")
|
log.Info("Starting index download")
|
||||||
repo.Status.Conditions = []sourcerv1.RepositoryCondition{readyCondition}
|
repo.Status.Conditions = []sourcev1.RepositoryCondition{readyCondition}
|
||||||
if err := r.Status().Update(ctx, &repo); err != nil {
|
if err := r.Status().Update(ctx, &repo); err != nil {
|
||||||
log.Error(err, "unable to update HelmRepository status")
|
log.Error(err, "unable to update HelmRepository status")
|
||||||
return ctrl.Result{}, err
|
return ctrl.Result{}, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, condition := range repo.Status.Conditions {
|
for _, condition := range repo.Status.Conditions {
|
||||||
if condition.Type == sourcerv1.RepositoryConditionReady {
|
if condition.Type == sourcev1.RepositoryConditionReady {
|
||||||
readyCondition = condition
|
readyCondition = condition
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -80,19 +81,19 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||||
|
|
||||||
if err := r.downloadIndex(repo.Spec.Url); err != nil {
|
if err := r.downloadIndex(repo.Spec.Url); err != nil {
|
||||||
log.Info("Index download error", "error", err.Error())
|
log.Info("Index download error", "error", err.Error())
|
||||||
readyCondition.Reason = sourcerv1.IndexDownloadFailedReason
|
readyCondition.Reason = sourcev1.IndexDownloadFailedReason
|
||||||
readyCondition.Message = err.Error()
|
readyCondition.Message = err.Error()
|
||||||
readyCondition.Status = corev1.ConditionFalse
|
readyCondition.Status = corev1.ConditionFalse
|
||||||
} else {
|
} else {
|
||||||
log.Info("Index download successful")
|
log.Info("Index download successful")
|
||||||
readyCondition.Reason = sourcerv1.IndexDownloadSucceedReason
|
readyCondition.Reason = sourcev1.IndexDownloadSucceedReason
|
||||||
readyCondition.Message = "Repository is ready"
|
readyCondition.Message = "Repository is ready"
|
||||||
readyCondition.Status = corev1.ConditionTrue
|
readyCondition.Status = corev1.ConditionTrue
|
||||||
}
|
}
|
||||||
|
|
||||||
timeNew := metav1.Now()
|
timeNew := metav1.Now()
|
||||||
readyCondition.LastTransitionTime = &timeNew
|
readyCondition.LastTransitionTime = &timeNew
|
||||||
repo.Status.Conditions = []sourcerv1.RepositoryCondition{readyCondition}
|
repo.Status.Conditions = []sourcev1.RepositoryCondition{readyCondition}
|
||||||
|
|
||||||
if err := r.Status().Update(ctx, &repo); err != nil {
|
if err := r.Status().Update(ctx, &repo); err != nil {
|
||||||
log.Error(err, "unable to update HelmRepository status")
|
log.Error(err, "unable to update HelmRepository status")
|
||||||
|
@ -104,7 +105,7 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
|
||||||
|
|
||||||
func (r *HelmRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *HelmRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
return ctrl.NewControllerManagedBy(mgr).
|
return ctrl.NewControllerManagedBy(mgr).
|
||||||
For(&sourcerv1.HelmRepository{}).
|
For(&sourcev1.HelmRepository{}).
|
||||||
WithEventFilter(RepositoryChangePredicate{}).
|
WithEventFilter(RepositoryChangePredicate{}).
|
||||||
Complete(r)
|
Complete(r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,5 +35,5 @@ func (RepositoryChangePredicate) Update(e event.UpdateEvent) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ForceSyncAnnotation string = "sourcer.fluxcd.io/syncAt"
|
ForceSyncAnnotation string = "source.fluxcd.io/syncAt"
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
sourcerv1alpha1 "github.com/fluxcd/sourcer/api/v1alpha1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
// +kubebuilder:scaffold:imports
|
// +kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,10 +62,10 @@ var _ = BeforeSuite(func(done Done) {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(cfg).ToNot(BeNil())
|
Expect(cfg).ToNot(BeNil())
|
||||||
|
|
||||||
err = sourcerv1alpha1.AddToScheme(scheme.Scheme)
|
err = sourcev1.AddToScheme(scheme.Scheme)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
err = sourcerv1alpha1.AddToScheme(scheme.Scheme)
|
err = sourcev1.AddToScheme(scheme.Scheme)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
// +kubebuilder:scaffold:scheme
|
// +kubebuilder:scaffold:scheme
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module github.com/fluxcd/sourcer
|
module github.com/fluxcd/source-controller
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
|
|
6
main.go
6
main.go
|
@ -29,8 +29,8 @@ import (
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||||
|
|
||||||
sourcerv1alpha1 "github.com/fluxcd/sourcer/api/v1alpha1"
|
sourcev1alpha1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
"github.com/fluxcd/sourcer/controllers"
|
"github.com/fluxcd/source-controller/controllers"
|
||||||
// +kubebuilder:scaffold:imports
|
// +kubebuilder:scaffold:imports
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
_ = clientgoscheme.AddToScheme(scheme)
|
_ = clientgoscheme.AddToScheme(scheme)
|
||||||
|
|
||||||
_ = sourcerv1alpha1.AddToScheme(scheme)
|
_ = sourcev1alpha1.AddToScheme(scheme)
|
||||||
// +kubebuilder:scaffold:scheme
|
// +kubebuilder:scaffold:scheme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue