Skip to content

Commit

Permalink
bump api to v1alpha2
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <[email protected]>
  • Loading branch information
chanwit committed Apr 15, 2023
1 parent 7575d4c commit c131204
Show file tree
Hide file tree
Showing 110 changed files with 7,039 additions and 156 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
# Generate API reference documentation
.PHONY: api-docs
api-docs: gen-crd-api-reference-docs
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1alpha1 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/References/terraform.md
$(GEN_CRD_API_REFERENCE_DOCS) -api-dir=./api/v1alpha2 -config=./hack/api-docs/config.json -template-dir=./hack/api-docs/template -out-file=./docs/References/terraform.md

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -137,35 +137,35 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build config/crd | kubectl apply --server-side -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/crd | kubectl delete --server-side --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image weaveworks/tf-controller=${MANAGER_IMG}:${TAG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
$(KUSTOMIZE) build config/default | kubectl apply --server-side -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build config/default | kubectl delete --server-side --ignore-not-found=$(ignore-not-found) -f -

# Deploy controller dev image in the configured Kubernetes cluster in ~/.kube/config
.PHONY: dev-deploy
dev-deploy: manifests kustomize
mkdir -p config/dev && cp config/default/* config/dev
cd config/dev && $(KUSTOMIZE) edit set image ghcr.io/weaveworks/tf-controller=${MANAGER_IMG}:${TAG}
$(KUSTOMIZE) build config/dev | yq e "select(.kind == \"Deployment\" and .metadata.name == \"tf-controller\").spec.template.spec.containers[0].env[1].value = \"test/tf-runner:$${TAG}\"" - | kubectl apply -f -
$(KUSTOMIZE) build config/dev | yq e "select(.kind == \"Deployment\" and .metadata.name == \"tf-controller\").spec.template.spec.containers[0].env[1].value = \"test/tf-runner:$${TAG}\"" - | kubectl apply --server-side -f -
rm -rf config/dev

# Delete dev deployment and CRDs
.PHONY: dev-cleanup
dev-cleanup: manifests kustomize
mkdir -p config/dev && cp config/default/* config/dev
cd config/dev && $(KUSTOMIZE) edit set image ghcr.io/weaveworks/tf-controller=${MANAGER_IMG}:${TAG}
$(KUSTOMIZE) build config/dev | kubectl delete -f -
$(KUSTOMIZE) build config/dev | kubectl delete --server-side -f -
rm -rf config/dev

KUSTOMIZE = $(shell pwd)/bin/kustomize
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ resources:
kind: Terraform
path: github.com/weaveworks/tf-controller/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: contrib.fluxcd.io
group: infra
kind: Terraform
path: github.com/weaveworks/tf-controller/api/v1alpha2
version: v1alpha2
version: "3"
1 change: 1 addition & 0 deletions api/v1alpha1/terraform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ type LockStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=tf
// +kubebuilder:subresource:status
// +kubebuilder:deprecatedversion:warning="v1alpha1 Terraform is deprecated, upgrade to v1alpha2"
// +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=""
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
Expand Down
36 changes: 36 additions & 0 deletions api/v1alpha2/cloud_spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package v1alpha2

import (
. "github.com/onsi/gomega"
"strings"
"testing"
)

// CloudSpec defines the desired state of Terraform Cloud
func TestCloudSpec(t *testing.T) {
g := NewGomegaWithT(t)
cloudSpec := &CloudSpec{
Organization: "test-org",
Workspaces: &CloudWorkspacesSpec{
Name: "dev",
Tags: []string{"test-tag", "test-tag-2"},
},
Hostname: "app.terraform.io",
Token: "test-token",
}

fixture := strings.TrimLeft(`
terraform {
cloud {
organization = "test-org"
workspaces {
name = "dev"
tags = ["test-tag", "test-tag-2"]
}
hostname = "app.terraform.io"
token = "test-token"
}
}
`, "\n")
g.Expect(cloudSpec.ToHCL()).To(Equal(fixture))
}
19 changes: 19 additions & 0 deletions api/v1alpha2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2021.
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.
*/

// +kubebuilder:object:generate=true
// +groupName=infra.contrib.fluxcd.io
package v1alpha2
36 changes: 36 additions & 0 deletions api/v1alpha2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2021.
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 infra v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=infra.contrib.fluxcd.io
package v1alpha2

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

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "infra.contrib.fluxcd.io", Version: "v1alpha2"}

// 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
)
35 changes: 35 additions & 0 deletions api/v1alpha2/inventory_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2021.
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 v1alpha2

// 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"`
}

// ResourceRef contains the information necessary to locate a resource within a cluster.
type ResourceRef struct {
// Terraform resource's name.
Name string `json:"n"`

// Type is Terraform resource's type
Type string `json:"t"`

// ID is the resource identifier. This is cloud-specific. For example, ARN is an ID on AWS.
Identifier string `json:"id"`
}
Loading

0 comments on commit c131204

Please sign in to comment.