Skip to content

Commit

Permalink
Merge pull request #8 from weaveworks/reconciliation-loop
Browse files Browse the repository at this point in the history
Initial reconciliation loop.
  • Loading branch information
bigkevmcd authored Oct 12, 2023
2 parents 001d61d + b13d985 commit 3c2aa74
Show file tree
Hide file tree
Showing 18 changed files with 1,319 additions and 252 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ COPY go.sum go.sum
COPY vendor vendor

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY main.go main.go
COPY api/ api/
COPY pkg/ pkg/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
go build -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/main.go
go run main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
Expand Down
10 changes: 10 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Steps before release of the AKS reflector

- [ ] Secret does not exist but cluster exists - Create a new secret
- [ ] Partial apply of clusters - ensure that subsequent reconciliations work
- [ ] Add managed-by labels!
- [ ] Conditions - ready with count of reflected clusters
- [ ] Events - publish when cluster created or removed
- [ ] Suspension
- [ ] Manually triggered reconciliation
- [ ] Provide for authentication via a Secret?
22 changes: 12 additions & 10 deletions api/v1alpha1/automatedclusterdiscovery_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// 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.

// AKS defines the desired state of AKS
type AKS struct {
// SubscriptionID is the Azure subscription ID
SubscriptionID string `json:"subscriptionId,omitempty"`
// +required
SubscriptionID string `json:"subscriptionID"`

Filter AKSFilter `json:"filter,omitempty"`

Expand All @@ -42,22 +40,26 @@ type AKSFilter struct {

// AutomatedClusterDiscoverySpec defines the desired state of AutomatedClusterDiscovery
type AutomatedClusterDiscoverySpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Name is the name of the cluster
Name string `json:"name,omitempty"`

// Type is the provider type
Type string `json:"type,omitempty"`
// +kubebuilder:validation:Enum=aks
Type string `json:"type"`

AKS *AKS `json:"aks,omitempty"`

// The interval at which to run the discovery
// +required
Interval metav1.Duration `json:"interval"`
}

// AutomatedClusterDiscoveryStatus defines the observed state of AutomatedClusterDiscovery
type AutomatedClusterDiscoveryStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Inventory contains the list of Kubernetes resource object references that
// have been successfully applied
// +optional
Inventory *ResourceInventory `json:"inventory,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
37 changes: 37 additions & 0 deletions api/v1alpha1/inventory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v1alpha1

import (
"fmt"

runtime "k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/cli-utils/pkg/object"
)

// ResourceInventory contains a list of Kubernetes resource object references that have been applied by a Kustomization.
type ResourceInventory struct {
// Entries of Kubernetes resource object references.
Entries []ResourceRef `json:"entries,omitempty"`
}

// ResourceRef contains the information necessary to locate a resource within a cluster.
type ResourceRef struct {
// ID is the string representation of the Kubernetes resource object's metadata,
// in the format '<namespace>_<name>_<group>_<kind>'.
ID string `json:"id"`

// Version is the API version of the Kubernetes resource object's kind.
Version string `json:"v"`
}

// ResourceRefFromObject returns a ResourceRef from a runtime.Object.
func ResourceRefFromObject(obj runtime.Object) (ResourceRef, error) {
objMeta, err := object.RuntimeToObjMeta(obj)
if err != nil {
return ResourceRef{}, fmt.Errorf("failed to parse object Metadata: %w", err)
}

return ResourceRef{
ID: objMeta.String(),
Version: obj.GetObjectKind().GroupVersionKind().Version,
}, nil
}
45 changes: 43 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

115 changes: 0 additions & 115 deletions cmd/main.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,55 @@ spec:
description: Location is the location of the AKS clusters
type: string
type: object
subscriptionId:
subscriptionID:
description: SubscriptionID is the Azure subscription ID
type: string
required:
- subscriptionID
type: object
interval:
description: The interval at which to run the discovery
type: string
name:
description: Name is the name of the cluster
type: string
type:
description: Type is the provider type
enum:
- aks
type: string
required:
- interval
- type
type: object
status:
description: AutomatedClusterDiscoveryStatus defines the observed state
of AutomatedClusterDiscovery
properties:
inventory:
description: Inventory contains the list of Kubernetes resource object
references that have been successfully applied
properties:
entries:
description: Entries of Kubernetes resource object references.
items:
description: ResourceRef contains the information necessary
to locate a resource within a cluster.
properties:
id:
description: ID is the string representation of the Kubernetes
resource object's metadata, in the format '<namespace>_<name>_<group>_<kind>'.
type: string
v:
description: Version is the API version of the Kubernetes
resource object's kind.
type: string
required:
- id
- v
type: object
type: array
type: object
type: object
type: object
served: true
Expand Down
Loading

0 comments on commit 3c2aa74

Please sign in to comment.