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

Provider api #183

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module github.com/cnoe-io/idpbuilder

go 1.21.3

toolchain go1.21.5
go 1.21.5

require (
code.gitea.io/sdk/gitea v0.16.0
github.com/cnoe-io/argocd-api v0.0.0-20240125015729-416a35fe855d
github.com/docker/docker v24.0.6+incompatible
github.com/go-git/go-git/v5 v5.10.0
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
k8s.io/api v0.29.1
k8s.io/apiextensions-apiserver v0.29.1
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
k8s.io/klog/v2 v2.110.1
sigs.k8s.io/controller-runtime v0.17.1
sigs.k8s.io/kind v0.20.0
sigs.k8s.io/yaml v1.4.0
Expand Down Expand Up @@ -46,8 +46,6 @@ require (
github.com/go-fed/httpsig v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand Down Expand Up @@ -92,8 +90,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.14.0 // indirect
Expand All @@ -115,7 +111,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/component-base v0.29.1 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/cnoe-io/idpbuilder/pkg/build"
"github.com/cnoe-io/idpbuilder/pkg/cmd/helpers"
"github.com/cnoe-io/idpbuilder/pkg/k8s"
k8s "github.com/cnoe-io/idpbuilder/pkg/k8s/clientutils"
"github.com/cnoe-io/idpbuilder/pkg/util"
"github.com/spf13/cobra"
"k8s.io/client-go/util/homedir"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"time"

"github.com/cnoe-io/idpbuilder/pkg/k8s"
k8s "github.com/cnoe-io/idpbuilder/pkg/k8s/clientutils"
"github.com/cnoe-io/idpbuilder/pkg/util"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/custompackage/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cnoe-io/idpbuilder/pkg/util"

argov1alpha1 "github.com/cnoe-io/argocd-api/api/argo/application/v1alpha1"
"github.com/cnoe-io/idpbuilder/pkg/k8s"
k8s "github.com/cnoe-io/idpbuilder/pkg/k8s/clientutils"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/localbuild/argo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package localbuild
import (
"testing"

"github.com/cnoe-io/idpbuilder/pkg/k8s"
k8s "github.com/cnoe-io/idpbuilder/pkg/k8s/clientutils"
"github.com/cnoe-io/idpbuilder/pkg/util"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/localbuild/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/cnoe-io/idpbuilder/pkg/k8s"
k8s "github.com/cnoe-io/idpbuilder/pkg/k8s/clientutils"
"github.com/cnoe-io/idpbuilder/pkg/util"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
35 changes: 14 additions & 21 deletions pkg/controllers/resources/idpbuilder.cnoe.io_custompackages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.12.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like you need to bump the version of your controller gen. are you using an older version of idpbuilder or is there any other reason to have this older version used?

name: custompackages.idpbuilder.cnoe.io
spec:
group: idpbuilder.cnoe.io
Expand All @@ -19,19 +19,14 @@ spec:
openAPIV3Schema:
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
Comment on lines -22 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these diffs will go away if a newer version of controller gen is used

type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down Expand Up @@ -65,14 +60,12 @@ spec:
- namespace
type: object
gitServerURL:
description: |-
GitServerURL specifies the base URL for the git server for API calls.
for example, https://gitea.cnoe.localtest.me:8443
description: GitServerURL specifies the base URL for the git server
for API calls. for example, https://gitea.cnoe.localtest.me:8443
type: string
internalGitServeURL:
description: |-
InternalGitServeURL specifies the base URL for the git server accessible within the cluster.
for example, http://my-gitea-http.gitea.svc.cluster.local:3000
description: InternalGitServeURL specifies the base URL for the git
server accessible within the cluster. for example, http://my-gitea-http.gitea.svc.cluster.local:3000
type: string
replicate:
default: false
Expand Down Expand Up @@ -103,9 +96,9 @@ spec:
type: object
type: array
synced:
description: |-
A Custom package is considered synced when the in-cluster repository url is set as the repository URL
This only applies for a package that references local directories
description: A Custom package is considered synced when the in-cluster
repository url is set as the repository URL This only applies for
a package that references local directories
type: boolean
type: object
type: object
Expand Down
25 changes: 10 additions & 15 deletions pkg/controllers/resources/idpbuilder.cnoe.io_gitrepositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.12.0
name: gitrepositories.idpbuilder.cnoe.io
spec:
group: idpbuilder.cnoe.io
Expand All @@ -19,19 +19,14 @@ spec:
openAPIV3Schema:
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down Expand Up @@ -68,9 +63,9 @@ spec:
- nginx
type: string
path:
description: |-
Path is the absolute path to directory that contains Kustomize structure or raw manifests.
This is required when Type is set to local.
description: Path is the absolute path to directory that contains
Kustomize structure or raw manifests. This is required when
Type is set to local.
type: string
type:
default: embedded
Expand Down
25 changes: 10 additions & 15 deletions pkg/controllers/resources/idpbuilder.cnoe.io_localbuilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.12.0
name: localbuilds.idpbuilder.cnoe.io
spec:
group: idpbuilder.cnoe.io
Expand All @@ -19,19 +19,14 @@ spec:
openAPIV3Schema:
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand All @@ -40,9 +35,9 @@ spec:
packageConfigs:
properties:
argoPackageConfigs:
description: |-
ArgoPackageConfigSpec Allows for configuration of the ArgoCD Installation.
If no fields are specified then the binary embedded resources will be used to intall ArgoCD.
description: ArgoPackageConfigSpec Allows for configuration of
the ArgoCD Installation. If no fields are specified then the
binary embedded resources will be used to intall ArgoCD.
properties:
enabled:
description: Enabled controls whether to install ArgoCD.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions pkg/k8s/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package k8s

import (
"fmt"

"github.com/cnoe-io/idpbuilder/pkg/k8s/provider"
"github.com/cnoe-io/idpbuilder/pkg/k8s/providers/kind"
)

func GetProvider(providerType provider.ProviderType, config *provider.Config) (provider.Provider, error) {
switch providerType {
case provider.KindProvider:
return kind.NewProvider()
}
return nil, fmt.Errorf("invalid provider type")
}
55 changes: 55 additions & 0 deletions pkg/k8s/provider/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package provider

import (
"context"

"sigs.k8s.io/kind/pkg/cluster/nodes"
)

type PortMapping struct {
HostPort string
ContainerPort string
}

type KindConfig struct {
KindConfigPath string
}
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to move the KindConfig definition under pkg/k8s/providers/kind for it to be self contained


// Configuration for providers
type Config struct {
KubernetesVersion string
ExtraPortsMapping []PortMapping
Port string
IngressProtocol string
Host string

Kind KindConfig
}

// This was mostly derived from sigs.k8s.io/kind/pkg/cluster/internal/providers
// We cannot import it directly as its an internal module

// Provider represents a provider of cluster / node infrastructure
type Provider interface {
// Provision should create the Kubernetes cluster
Provision(ctx context.Context, clusterName string, config *Config) error
// ListClusters discovers the clusters that currently have resources
// under this providers
ListClusters() ([]string, error)
// ListNodes returns the nodes under this provider for the given
// cluster name, they may or may not be running correctly
Delete(clusterName string) error
ListNodes(clusterName string) ([]nodes.Node, error)
// GetAPIServerEndpoint returns the host endpoint for the cluster's API server
GetAPIServerEndpoint(clusterName string) (string, error)
// GetAPIServerInternalEndpoint returns the internal network endpoint for the cluster's API server
GetAPIServerInternalEndpoint(clusterName string) (string, error)
// ExportKubeConfig writes out kube config under name to path
ExportKubeConfig(clusterName string, path string, internal bool) error
}

type ProviderType string

const (
KindProvider ProviderType = "Kind"
)
Loading
Loading