Skip to content

Commit

Permalink
feat: Implement reconcile logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yiannistri committed Mar 28, 2022
1 parent 8e725c6 commit e846068
Show file tree
Hide file tree
Showing 22 changed files with 924 additions and 223 deletions.
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Development

## How to run the test suite

Prerequisites:
* Go >= 1.17
* clusterctl >= 1.1.3

You can run the test suite by simply doing

```sh
make test
```

## How to run the controller locally

Ensure the cluster you are using has the CAPI CRDs installed as the controller references them. If necessary, run the `clusterctl init` command:
```sh
clusterctl init
```

Install the controller's CRDs on your test cluster:

```sh
make install
```

Run the controller locally:

```sh
make run
```
2 changes: 1 addition & 1 deletion PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resources:
controller: true
domain: weave.works
group: gitops
kind: Cluster
kind: GitopsCluster
path: github.com/weaveworks/cluster-controller/api/v1alpha1
version: v1alpha1
version: "3"
64 changes: 0 additions & 64 deletions api/v1alpha1/cluster_types.go

This file was deleted.

12 changes: 12 additions & 0 deletions api/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v1alpha1

const (
// SecretFoundReason signals that a given secret has been found.
SecretFoundReason string = "SecretFound"
// WaitingForSecretReason signals that a given secret has not been found.
WaitingForSecretReason string = "WaitingForSecret"
// CAPIClusterFoundReason signals that a given CAPI cluster has been found.
CAPIClusterFoundReason string = "CAPIClusterFound"
// WaitingForCAPIClusterReason signals that a given CAPI cluster has not been found.
WaitingForCAPIClusterReason string = "WaitingForCAPICluster"
)
81 changes: 81 additions & 0 deletions api/v1alpha1/gitopscluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2022.
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"

"github.com/fluxcd/pkg/apis/meta"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// GitopsClusterSpec defines the desired state of GitopsCluster
type GitopsClusterSpec struct {
// SecretRef specifies the Secret containing the kubeconfig for a cluster.
// +optional
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
// CAPIClusterRef specifies the CAPI Cluster.
// +optional
CAPIClusterRef *meta.LocalObjectReference `json:"capiClusterRef,omitempty"`
}

// GitopsClusterStatus defines the observed state of GitopsCluster
type GitopsClusterStatus struct {
// Conditions holds the conditions for the Cluster.
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// GetConditions returns the status conditions of the object.
func (in GitopsCluster) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// SetConditions sets the status conditions on the object.
func (in *GitopsCluster) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""

// GitopsCluster is the Schema for the gitopsclusters API
type GitopsCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GitopsClusterSpec `json:"spec,omitempty"`
Status GitopsClusterStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&GitopsCluster{}, &GitopsClusterList{})
}
61 changes: 40 additions & 21 deletions api/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit e846068

Please sign in to comment.