Skip to content

Commit bd084d0

Browse files
ErikJiangpacoxu
authored andcommitted
update scaffolding && support tilt local deployment
Signed-off-by: bo.jiang <bo.jiang@daocloud.io>
1 parent 7cc12b1 commit bd084d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+780
-374
lines changed

.gitignore

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
# Binaries
1+
# Binaries for programs and plugins
22
*.exe
33
*.exe~
44
*.dll
55
*.so
66
*.dylib
7-
bin/
7+
bin/*
8+
Dockerfile.cross
89

9-
# Test binary, build with `go test -c`
10+
# Test binary, built with `go test -c`
1011
*.test
1112

1213
# Output of the go coverage tool, specifically when used with LiteIDE
1314
*.out
1415

15-
# goland
16-
.idea
16+
# Go workspace file
17+
go.work
1718

18-
.DS_Store
19+
# Kubernetes Generated files - skip generated files, except for vendored files
20+
!vendor/**/zz_generated.*
1921

20-
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
21-
# Ignore build and test binaries.
22-
bin/
23-
testbin/
22+
# editor and IDE paraphernalia
23+
.idea
24+
.vscode
25+
*.swp
26+
*.swo
27+
*~
28+
.tiltbuild/*

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
15+
COPY ./ ./
1816

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

2624
# Use distroless as minimal base image to package the manager binary
2725
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Image URL to use all building/pushing image targets
2-
IMG ?= controller:latest
2+
IMG ?= gcr.io/k8s-staging-cluster-api-huawei/cluster-api-huawei-controller:latest
33
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
44
ENVTEST_K8S_VERSION = 1.31.0
55

@@ -92,11 +92,11 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
9292

9393
.PHONY: build
9494
build: manifests generate fmt vet ## Build manager binary.
95-
go build -o bin/manager cmd/main.go
95+
go build -o bin/manager main.go
9696

9797
.PHONY: run
9898
run: manifests generate fmt vet ## Run a controller from your host.
99-
go run ./cmd/main.go
99+
go run ./main.go
100100

101101
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
102102
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
@@ -130,7 +130,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
130130
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
131131
mkdir -p dist
132132
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
133-
$(KUSTOMIZE) build config/default > dist/install.yaml
133+
$(KUSTOMIZE) build config/default | envsubst > dist/install.yaml
134134

135135
##@ Deployment
136136

@@ -149,11 +149,11 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
149149
.PHONY: deploy
150150
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
151151
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
152-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
152+
$(KUSTOMIZE) build config/default | envsubst | $(KUBECTL) apply -f -
153153

154154
.PHONY: undeploy
155155
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
156-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
156+
$(KUSTOMIZE) build config/default | envsubst | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
157157

158158
##@ Dependencies
159159

PROJECT

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@ domain: cluster.x-k8s.io
66
layout:
77
- go.kubebuilder.io/v4
88
projectName: cluster-api-provider-huawei
9-
repo: github.com/HuaweiCloudDeveloper/cluster-api-provider-Huawei
9+
repo: github.com/HuaweiCloudDeveloper/cluster-api-provider-huawei
1010
resources:
1111
- api:
1212
crdVersion: v1
1313
namespaced: true
1414
controller: true
1515
domain: cluster.x-k8s.io
1616
group: infrastructure
17-
kind: HuaweiCloudMachine
18-
path: github.com/HuaweiCloudDeveloper/cluster-api-provider-Huawei/api/v1alpha1
17+
kind: HuaweiCloudCluster
18+
path: github.com/HuaweiCloudDeveloper/cluster-api-provider-huawei/api/v1alpha1
1919
version: v1alpha1
2020
- api:
2121
crdVersion: v1
2222
namespaced: true
2323
controller: true
2424
domain: cluster.x-k8s.io
2525
group: infrastructure
26-
kind: HuaweiCloudCluster
27-
path: github.com/HuaweiCloudDeveloper/cluster-api-provider-Huawei/api/v1alpha1
26+
kind: HuaweiCloudMachine
27+
path: github.com/HuaweiCloudDeveloper/cluster-api-provider-huawei/api/v1alpha1
28+
version: v1alpha1
29+
- api:
30+
crdVersion: v1
31+
namespaced: true
32+
domain: cluster.x-k8s.io
33+
group: infrastructure
34+
kind: HuaweiCloudMachineTemplate
35+
path: github.com/HuaweiCloudDeveloper/cluster-api-provider-huawei/api/v1alpha1
2836
version: v1alpha1
2937
version: "3"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Kubernetes-native declarative infrastructure for [Huawei Cloud](https://www.huaweicloud.com/).
44

55
<!-- goreportcard badge -->
6-
<a href="https://goreportcard.com/report/HuaweiCloudDeveloper/cluster-api-provider-Huawei">
7-
<img src="https://goreportcard.com/badge/HuaweiCloudDeveloper/cluster-api-provider-Huawei"></a>
6+
<a href="https://goreportcard.com/report/HuaweiCloudDeveloper/cluster-api-provider-huawei">
7+
<img src="https://goreportcard.com/badge/HuaweiCloudDeveloper/cluster-api-provider-huawei"></a>
88

99
## What is the Cluster API Provider Huawei Cloud?
1010

1111
The Cluster API Provider Huawei Cloud is a Kubernetes project to bring declarative,
1212
Kubernetes-style APIs to cluster creation, configuration, and management.
1313
It provides optional, additive functionality on top of [Cluster API](https://github.com/kubernetes-sigs/cluster-api)
14-
to deploy and manage Kubernetes clusters on Huawei Cloud.
14+
to deploy and manage Kubernetes clusters on Huawei Cloud.

api/v1alpha1/groupversion_info.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024.
2+
Copyright 2025.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -20,26 +20,17 @@ limitations under the License.
2020
package v1alpha1
2121

2222
import (
23-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
"k8s.io/apimachinery/pkg/runtime"
2523
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
2625
)
2726

2827
var (
2928
// GroupVersion is group version used to register these objects.
3029
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1alpha1"}
3130

32-
// schemeBuilder is used to add go types to the GroupVersionKind scheme.
33-
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3433

3534
// AddToScheme adds the types in this group-version to the given scheme.
36-
AddToScheme = schemeBuilder.AddToScheme
37-
38-
objectTypes = []runtime.Object{}
35+
AddToScheme = SchemeBuilder.AddToScheme
3936
)
40-
41-
func addKnownTypes(scheme *runtime.Scheme) error {
42-
scheme.AddKnownTypes(GroupVersion, objectTypes...)
43-
metav1.AddToGroupVersion(scheme, GroupVersion)
44-
return nil
45-
}

api/v1alpha1/huaweicloudcluster_types.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024.
2+
Copyright 2025.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2221
)
2322

2423
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -29,15 +28,8 @@ type HuaweiCloudClusterSpec struct {
2928
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3029
// Important: Run "make" to regenerate code after modifying this file
3130

32-
// The ECS Region the cluster lives in.
33-
Region string `json:"region,omitempty"`
34-
35-
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
36-
// +optional
37-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
38-
39-
// TODO, Network related fields need to be defined in the future
40-
// other fields may like S3, SSHKey, etc.
31+
// Foo is an example field of HuaweiCloudCluster. Edit huaweicloudcluster_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
4133
}
4234

4335
// HuaweiCloudClusterStatus defines the observed state of HuaweiCloudCluster.
@@ -68,5 +60,5 @@ type HuaweiCloudClusterList struct {
6860
}
6961

7062
func init() {
71-
objectTypes = append(objectTypes, &HuaweiCloudCluster{}, &HuaweiCloudClusterList{})
63+
SchemeBuilder.Register(&HuaweiCloudCluster{}, &HuaweiCloudClusterList{})
7264
}
Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024.
2+
Copyright 2025.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -18,69 +18,24 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2221
)
2322

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

2726
// HuaweiCloudMachineSpec defines the desired state of HuaweiCloudMachine.
28-
// Most attributes are referred to https://github.com/huaweicloud/huaweicloud-sdk-go-v3/blob/master/services/ecs/v2/model/model_nova_create_servers_option.go
2927
type HuaweiCloudMachineSpec struct {
3028
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
3129
// Important: Run "make" to regenerate code after modifying this file
3230

33-
// 弹性云服务器uuid。
34-
// ProviderID is the unique identifier as specified by the cloud provider.
35-
ProviderID *string `json:"providerID,omitempty"`
36-
37-
// InstanceID is the ECS instance ID for this machine.
38-
InstanceID *string `json:"instanceID,omitempty"`
39-
40-
// 镜像ID或者镜像资源的URL
41-
// ImageRef is the reference from which to create the machine instance.
42-
ImageRef *string `json:"imageRef,omitempty"`
43-
44-
// FlavorRef is similar to instanceType.
45-
// FlavorRef is the type of instance to create. Example: s2.small.1
46-
// +kubebuilder:validation:Required
47-
// +kubebuilder:validation:MinLength:=2
48-
FlavorRef string `json:"flavorRef"`
49-
50-
// TODO, need to define the type of Volume struct in the future
51-
// RootVolume encapsulates the configuration options for the root volume
52-
// +optional
53-
// RootVolume *model.RootVolume `json:"rootVolume,omitempty"`
54-
// Configuration options for the data storage volumes.
55-
// +optional
56-
// DataVolumes *[]model.DataVolumes `json:"dataVolumes,omitempty"`
57-
58-
// TODO, more fields need to be defined in the future
59-
// AdminPass *string `json:"admin_pass,omitempty"`
60-
// NetConfig *NetConfig `json:"net_config"`
61-
// Bandwidth *BandwidthConfig `json:"bandwidth,omitempty"`
31+
// Foo is an example field of HuaweiCloudMachine. Edit huaweicloudmachine_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
6233
}
6334

6435
// HuaweiCloudMachineStatus defines the observed state of HuaweiCloudMachine.
6536
type HuaweiCloudMachineStatus struct {
6637
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
6738
// Important: Run "make" to regenerate code after modifying this file
68-
69-
// Ready is true when the provider resource is ready.
70-
// +optional
71-
Ready bool `json:"ready"`
72-
73-
// Addresses contains the ECS instance associated addresses.
74-
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
75-
76-
// InstanceState is the state of the ECS instance for this machine.
77-
// +optional
78-
InstanceState *InstanceState `json:"instanceState,omitempty"`
79-
80-
// +optional
81-
FailureMessage *string `json:"failureMessage,omitempty"`
82-
83-
// TODO add conditions and more fields in the future
8439
}
8540

8641
// +kubebuilder:object:root=true
@@ -105,5 +60,5 @@ type HuaweiCloudMachineList struct {
10560
}
10661

10762
func init() {
108-
objectTypes = append(objectTypes, &HuaweiCloudMachine{}, &HuaweiCloudMachineList{})
63+
SchemeBuilder.Register(&HuaweiCloudMachine{}, &HuaweiCloudMachineList{})
10964
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// HuaweiCloudMachineTemplateSpec defines the desired state of HuaweiCloudMachineTemplate.
27+
type HuaweiCloudMachineTemplateSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of HuaweiCloudMachineTemplate. Edit huaweicloudmachinetemplate_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// HuaweiCloudMachineTemplateStatus defines the observed state of HuaweiCloudMachineTemplate.
36+
type HuaweiCloudMachineTemplateStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
// +kubebuilder:object:root=true
42+
// +kubebuilder:subresource:status
43+
44+
// HuaweiCloudMachineTemplate is the Schema for the huaweicloudmachinetemplates API.
45+
type HuaweiCloudMachineTemplate struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec HuaweiCloudMachineTemplateSpec `json:"spec,omitempty"`
50+
Status HuaweiCloudMachineTemplateStatus `json:"status,omitempty"`
51+
}
52+
53+
// +kubebuilder:object:root=true
54+
55+
// HuaweiCloudMachineTemplateList contains a list of HuaweiCloudMachineTemplate.
56+
type HuaweiCloudMachineTemplateList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []HuaweiCloudMachineTemplate `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&HuaweiCloudMachineTemplate{}, &HuaweiCloudMachineTemplateList{})
64+
}

0 commit comments

Comments
 (0)