Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy over CAPT APIs to local package #9114

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/controlplaneupgrade_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
tinkerbellv1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/aws/eks-anywhere/controllers"
"github.com/aws/eks-anywhere/controllers/mocks"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
tinkerbellv1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1"
"github.com/aws/eks-anywhere/pkg/constants"
)

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.9.0
github.com/tinkerbell/cluster-api-provider-tinkerbell v0.1.1-0.20220615214617-9e9c2a397288
github.com/tinkerbell/tink v0.8.0
github.com/vmware/govmomi v0.37.2
go.uber.org/zap v1.26.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,6 @@ github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tinkerbell/cluster-api-provider-tinkerbell v0.1.1-0.20220615214617-9e9c2a397288 h1:HkBPnM4/DdLKJvcUNsFePYuTAFOHPMSzr3DvH7ZKBds=
github.com/tinkerbell/cluster-api-provider-tinkerbell v0.1.1-0.20220615214617-9e9c2a397288/go.mod h1:IjRbGnQtoplJEW5UgKHsCp1WukkAyjhIdDBsxjYq2dM=
github.com/tinkerbell/tink v0.8.0 h1:qgl/rglpO5Rvq6UKZd29O6X9mDgZZYgf841+Y0IYWak=
github.com/tinkerbell/tink v0.8.0/go.mod h1:bfAkSH7J/QQYIyqZRR6IQp8w78aac6l8Z2Lws5uXz6A=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"

v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/eks-anywhere/internal/aws-sdk-go-v2/internal/sdk"
"github.com/aws/smithy-go"
"github.com/aws/smithy-go/auth"
"github.com/aws/smithy-go/logging"
smithyhttp "github.com/aws/smithy-go/transport/http"

"github.com/aws/eks-anywhere/internal/aws-sdk-go-v2/internal/sdk"
)

// V4SignerAdapter adapts v4.HTTPSigner to smithy http.Signer.
Expand Down
3 changes: 1 addition & 2 deletions internal/aws-sdk-go-v2/internal/endpoints/v2/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"regexp"
"strings"

"github.com/aws/smithy-go/logging"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/smithy-go/logging"
)

// DefaultKey is a compound map key of a variant and other values.
Expand Down
4 changes: 2 additions & 2 deletions internal/test/e2e/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

const (
packagesRegex = `^.*CuratedPackages.*$`
packagesRegex = `^.*CuratedPackages.*$`
nonRegionalPackagesRegex = `^.*NonRegionalCuratedPackages.*$`
certManagerRegex = "^.*CuratedPackagesCertManager.*$"
certManagerRegex = "^.*CuratedPackagesCertManager.*$"
)

func (e *E2ESession) setupPackagesEnv(testRegex string) error {
Expand Down
734 changes: 734 additions & 0 deletions internal/test/envtest/config/capt-crds.yaml

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions internal/test/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

eksdv1alpha1 "github.com/aws/eks-distro-build-tooling/release/api/v1alpha1"
etcdv1 "github.com/aws/etcdadm-controller/api/v1beta1"
tinkerbellv1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
tinkv1alpha1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -39,6 +38,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
tinkerbellv1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1"
rufiov1alpha1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell/rufio"
snowv1 "github.com/aws/eks-anywhere/pkg/providers/snow/api/v1beta1"
releasev1 "github.com/aws/eks-anywhere/release/api/v1alpha1"
Expand All @@ -48,7 +48,6 @@ const (
capiPackage = "sigs.k8s.io/cluster-api"
capdPackage = "sigs.k8s.io/cluster-api/test"
capvPackage = "sigs.k8s.io/cluster-api-provider-vsphere"
captPackage = "github.com/tinkerbell/cluster-api-provider-tinkerbell"
tinkerbellPackage = "github.com/tinkerbell/tink"
etcdProviderPackage = "github.com/aws/etcdadm-controller"
capcPackage = "sigs.k8s.io/cluster-api-provider-cloudstack"
Expand Down Expand Up @@ -83,9 +82,6 @@ var packages = []moduleWithCRD{
withAdditionalCustomCRDPath("bootstrap/kubeadm/config/crd/bases"),
withAdditionalCustomCRDPath("controlplane/kubeadm/config/crd/bases"),
),
mustBuildModuleWithCRDs(captPackage,
withMainCustomCRDPath("config/crd/bases/infrastructure.cluster.x-k8s.io_tinkerbellclusters.yaml"),
withAdditionalCustomCRDPath("config/crd/bases/infrastructure.cluster.x-k8s.io_tinkerbellmachinetemplates.yaml")),
mustBuildModuleWithCRDs(tinkerbellPackage),
mustBuildModuleWithCRDs(capvPackage,
withMainCustomCRDPath("config/default/crd/bases"),
Expand Down Expand Up @@ -153,6 +149,7 @@ func newEnvironment(ctx context.Context) (*Environment, error) {
filepath.Join(currentDir, "config", "eks-d-crds.yaml"),
filepath.Join(currentDir, "config", "snow-crds.yaml"),
filepath.Join(currentDir, "config", "rufio-crds.yaml"),
filepath.Join(currentDir, "config", "capt-crds.yaml"),
filepath.Join(root, "internal", "thirdparty", "capc", "config", "crd", "bases"),
)
extraCRDPaths, err := getPathsToPackagesCRDs(root, packages...)
Expand Down
2 changes: 1 addition & 1 deletion manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/go-logr/logr"
nutanixv1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
"github.com/spf13/pflag"
tinkerbellv1 "github.com/tinkerbell/cluster-api-provider-tinkerbell/api/v1beta1"
tinkv1alpha1 "github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -34,6 +33,7 @@ import (

"github.com/aws/eks-anywhere/controllers"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
tinkerbellv1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1"
rufiov1alpha1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1/thirdparty/tinkerbell/rufio"
"github.com/aws/eks-anywhere/pkg/clusterapi"
"github.com/aws/eks-anywhere/pkg/controller/clientutil"
Expand Down
18 changes: 18 additions & 0 deletions pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Tinkerbell Authors.

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 v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group.
package v1beta1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2022 The Tinkerbell Authors.

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=infrastructure.cluster.x-k8s.io

package v1beta1

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

//nolint:gochecknoglobals
var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "infrastructure.cluster.x-k8s.io", Version: "v1beta1"}

// 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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2022 The Tinkerbell Authors.

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 v1beta1

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

const (
// ClusterFinalizer allows ReconcileTinkerbellCluster to clean up Tinkerbell resources before
// removing it from the apiserver.
ClusterFinalizer = "tinkerbellcluster.infrastructure.cluster.x-k8s.io"
)

// TinkerbellClusterSpec defines the desired state of TinkerbellCluster.
type TinkerbellClusterSpec struct {
// ControlPlaneEndpoint is a required field by ClusterAPI v1beta1.
//
// See https://cluster-api.sigs.k8s.io/developer/architecture/controllers/cluster.html
// for more details.
//
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint,omitempty"`

// ImageLookupFormat is the URL naming format to use for machine images when
// a machine does not specify. When set, this will be used for all cluster machines
// unless a machine specifies a different ImageLookupFormat. Supports substitutions
// for {{.BaseRegistry}}, {{.OSDistro}}, {{.OSVersion}} and {{.KubernetesVersion}} with
// the basse URL, OS distribution, OS version, and kubernetes version, respectively.
// BaseRegistry will be the value in ImageLookupBaseRegistry or ghcr.io/tinkerbell/cluster-api-provider-tinkerbell
// (the default), OSDistro will be the value in ImageLookupOSDistro or ubuntu (the default),
// OSVersion will be the value in ImageLookupOSVersion or default based on the OSDistro
// (if known), and the kubernetes version as defined by the packages produced by
// kubernetes/release: v1.13.0, v1.12.5-mybuild.1, or v1.17.3. For example, the default
// image format of {{.BaseRegistry}}/{{.OSDistro}}-{{.OSVersion}}:{{.KubernetesVersion}}.gz will
// attempt to pull the image from that location. See also: https://golang.org/pkg/text/template/
// +optional
ImageLookupFormat string `json:"imageLookupFormat,omitempty"`

// ImageLookupBaseRegistry is the base Registry URL that is used for pulling images,
// if not set, the default will be to use ghcr.io/tinkerbell/cluster-api-provider-tinkerbell.
// +optional
// +kubebuilder:default=ghcr.io/tinkerbell/cluster-api-provider-tinkerbell
ImageLookupBaseRegistry string `json:"imageLookupBaseRegistry,omitempty"`

// ImageLookupOSDistro is the name of the OS distro to use when fetching machine images,
// if not set it will default to ubuntu.
// +optional
// +kubebuilder:default=ubuntu
ImageLookupOSDistro string `json:"imageLookupOSDistro,omitempty"`

// ImageLookupOSVersion is the version of the OS distribution to use when fetching machine
// images. If not set it will default based on ImageLookupOSDistro.
// +optional
ImageLookupOSVersion string `json:"imageLookupOSVersion,omitempty"`
}

// TinkerbellClusterStatus defines the observed state of TinkerbellCluster.
type TinkerbellClusterStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file.

// Ready denotes that the cluster (infrastructure) is ready.
// +optional
Ready bool `json:"ready"`
}

// +kubebuilder:subresource:status
// +kubebuilder:resource:path=tinkerbellclusters,scope=Namespaced,categories=cluster-api
// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this TinkerbellCluster belongs"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="TinkerbellCluster ready status"

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

Spec TinkerbellClusterSpec `json:"spec,omitempty"`
Status TinkerbellClusterStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

//nolint:gochecknoinits
func init() {
SchemeBuilder.Register(&TinkerbellCluster{}, &TinkerbellClusterList{})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2022 The Tinkerbell Authors.

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 v1beta1

import (
"strings"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

const (
osUbuntu = "ubuntu"
defaultUbuntuVersion = "20.04"
)

var _ admission.Validator = &TinkerbellCluster{}

// SetupWebhookWithManager sets up and registers the webhook with the manager.
func (c *TinkerbellCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).For(c).Complete() //nolint:wrapcheck

Check warning on line 36 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}

// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-tinkerbellcluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=tinkerbellclusters,versions=v1beta1,name=validation.tinkerbellcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
// +kubebuilder:webhook:verbs=create;update,path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-tinkerbellcluster,mutating=true,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=tinkerbellclusters,versions=v1beta1,name=default.tinkerbellcluster.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1;v1beta1

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (c *TinkerbellCluster) ValidateCreate() (admission.Warnings, error) {
return nil, nil

Check warning on line 44 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L43-L44

Added lines #L43 - L44 were not covered by tests
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *TinkerbellCluster) ValidateUpdate(_ runtime.Object) (admission.Warnings, error) {
return nil, nil

Check warning on line 49 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L48-L49

Added lines #L48 - L49 were not covered by tests
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *TinkerbellCluster) ValidateDelete() (admission.Warnings, error) {
return nil, nil

Check warning on line 54 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L53-L54

Added lines #L53 - L54 were not covered by tests
}

func defaultVersionForOSDistro(distro string) string {
if strings.ToLower(distro) == osUbuntu {
return defaultUbuntuVersion
}

Check warning on line 60 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L57-L60

Added lines #L57 - L60 were not covered by tests

return ""

Check warning on line 62 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L62

Added line #L62 was not covered by tests
}

// Default implements webhookutil.defaulter so a webhook will be registered for the type.
func (c *TinkerbellCluster) Default() {
if c.Spec.ImageLookupFormat == "" {
c.Spec.ImageLookupFormat = "{{.BaseRegistry}}/{{.OSDistro}}-{{.OSVersion}}:{{.KubernetesVersion}}.gz"
}

Check warning on line 69 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L66-L69

Added lines #L66 - L69 were not covered by tests

if c.Spec.ImageLookupOSVersion == "" {
c.Spec.ImageLookupOSVersion = defaultVersionForOSDistro(c.Spec.ImageLookupOSDistro)
}

Check warning on line 73 in pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/v1alpha1/thirdparty/tinkerbell/capt/v1beta1/tinkerbellcluster_webhook.go#L71-L73

Added lines #L71 - L73 were not covered by tests
}
Loading
Loading