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

Add Openshift cluster client #344

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1320e82
Update sdk version
sergenyalcin Feb 11, 2022
4e71a26
Bump Go version to v1.17
ulucinar Apr 5, 2022
926c017
Bump Crossplane Runtime and Tools to latest
turkenh Mar 31, 2022
c8230b4
Add StoreConfig type
turkenh Mar 31, 2022
bd0ae2e
Add Secret Store connection manager as publisher if enabled
turkenh Apr 1, 2022
3495b88
Add example for StoreConfig
turkenh Apr 1, 2022
e53c078
Bump go version to 1.17
turkenh Apr 1, 2022
4904431
Fix unit tests by using crossplane runtime error package
turkenh Apr 6, 2022
40bd81e
Bump linter version
ulucinar Apr 7, 2022
0242ede
Add nil check for IPConfigurationPropertiesFormat
sergenyalcin May 13, 2022
e1a1072
Move from crossplane org to crossplane-contrib
negz May 27, 2022
96532e8
Switch build machinery from crossplane to crossplane-contrib org
negz May 27, 2022
ca3e5d4
Add openshift cluster support
dorroddorrod Jun 21, 2022
16bfadb
Update azure-provider.yaml
dorroddorrod Jun 21, 2022
e06eef0
Update azure-provider.yaml
dorroddorrod Jun 21, 2022
6b8340c
Add openshift cluster support
dorroddorrod Jun 21, 2022
73e8c88
Update azure-provider.yaml
dorroddorrod Jun 21, 2022
6f399f9
Update azure-provider.yaml
dorroddorrod Jun 21, 2022
8b53ef0
Merge branch 'master' into master
dormullor Jun 22, 2022
fa7942b
Add signoff author
dorroddorrod Jun 23, 2022
5439588
Merge branch 'master' of https://github.com/dorroddorrod/provider-azure
dorroddorrod Jun 23, 2022
8355b2b
Update openshift.yaml
dormullor Jun 24, 2022
23a0a7c
Fix service principal permissions
dorroddorrod Jun 24, 2022
ae7d772
Fix service principal permissions
dorroddorrod Jun 25, 2022
e2fafa2
Decode kubeconfig
dorroddorrod Jul 12, 2022
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
57 changes: 55 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ PROJECT_REPO := github.com/crossplane-contrib/$(PROJECT_NAME)
PLATFORMS ?= linux_amd64 linux_arm64

# kind-related versions
KIND_VERSION ?= v0.11.1
KIND_NODE_IMAGE_TAG ?= v1.23.1
KIND_VERSION ?= v0.12.0
KIND_NODE_IMAGE_TAG ?= v1.23.4

# -include will silently skip missing files, which allows us
# to load those files with a target in the Makefile. If only
# "include" was used, the make command would fail and refuse
Expand Down Expand Up @@ -112,6 +113,21 @@ run: go.build
@# To see other arguments that can be provided, run the command with --help instead
$(GO_OUT_DIR)/provider --debug

dev: $(KIND) $(KUBECTL)
@$(INFO) Creating kind cluster
@$(KIND) create cluster --name=$(PROJECT_NAME)-dev
@$(KUBECTL) cluster-info --context kind-$(PROJECT_NAME)-dev
@$(INFO) Installing Crossplane CRDs
@$(KUBECTL) apply -k https://github.com/crossplane/crossplane//cluster?ref=master
@$(INFO) Installing Provider Openshift CRDs
@$(KUBECTL) apply -R -f package/crds
@$(INFO) Starting Provider Openshift controllers
@$(GO) run cmd/provider/main.go --debug

dev-clean: $(KIND) $(KUBECTL)
@$(INFO) Deleting kind cluster
@$(KIND) delete cluster --name=$(PROJECT_NAME)-dev

manifests:
@$(WARN) Deprecated. Please run make generate instead.

Expand All @@ -131,6 +147,43 @@ test.init: $(KUBEBUILDER)

# ====================================================================================
# Special Targets
# Install gomplate
GOMPLATE_VERSION := 3.10.0
GOMPLATE := $(TOOLS_HOST_DIR)/gomplate-$(GOMPLATE_VERSION)

$(GOMPLATE):
@$(INFO) installing gomplate $(SAFEHOSTPLATFORM)
@mkdir -p $(TOOLS_HOST_DIR)
@curl -fsSLo $(GOMPLATE) https://github.com/hairyhenderson/gomplate/releases/download/v$(GOMPLATE_VERSION)/gomplate_$(SAFEHOSTPLATFORM) || $(FAIL)
@chmod +x $(GOMPLATE)
@$(OK) installing gomplate $(SAFEHOSTPLATFORM)

export GOMPLATE

# This target prepares repo for your provider by replacing all "openshift"
# occurrences with your provider name.
# This target can only be run once, if you want to rerun for some reason,
# consider stashing/resetting your git state.
# Arguments:
# provider: Camel case name of your provider, e.g. GitHub, PlanetScale
provider.prepare:
@[ "${provider}" ] || ( echo "argument \"provider\" is not set"; exit 1 )
@PROVIDER=$(provider) ./hack/helpers/prepare.sh

# This target adds a new api type and its controller.
# You would still need to register new api in "apis/<provider>.go" and
# controller in "internal/controller/<provider>.go".
# Arguments:
# provider: Camel case name of your provider, e.g. GitHub, PlanetScale
# group: API group for the type you want to add.
# kind: Kind of the type you want to add
# apiversion: API version of the type you want to add. Optional and defaults to "v1alpha1"
provider.addtype: $(GOMPLATE)
@[ "${provider}" ] || ( echo "argument \"provider\" is not set"; exit 1 )
@[ "${group}" ] || ( echo "argument \"group\" is not set"; exit 1 )
@[ "${kind}" ] || ( echo "argument \"kind\" is not set"; exit 1 )
@PROVIDER=$(provider) GROUP=$(group) KIND=$(kind) APIVERSION=$(apiversion) ./hack/helpers/addtype.sh


define CROSSPLANE_MAKE_HELP
Crossplane Targets:
Expand Down
2 changes: 2 additions & 0 deletions apis/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
azurev1alpha1 "github.com/crossplane-contrib/provider-azure/apis/v1alpha1"
azurev1alpha3 "github.com/crossplane-contrib/provider-azure/apis/v1alpha3"
azurev1beta1 "github.com/crossplane-contrib/provider-azure/apis/v1beta1"
openshiftv1alpha1 "github.com/crossplane-contrib/provider-azure/apis/containers/v1alpha1"
)

func init() {
Expand All @@ -47,6 +48,7 @@ func init() {
networkv1alpha3.SchemeBuilder.AddToScheme,
storagev1alpha3.SchemeBuilder.AddToScheme,
dnsv1alpha1.SchemeBuilder.AddToScheme,
openshiftv1alpha1.SchemeBuilder.AddToScheme,
)
}

Expand Down
18 changes: 18 additions & 0 deletions apis/containers/containers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Crossplane 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 openshift contains group openshift API versions
package containers
17 changes: 17 additions & 0 deletions apis/containers/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2022 The Crossplane 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 v1alpha1
40 changes: 40 additions & 0 deletions apis/containers/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2020 The Crossplane 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 v1alpha1 contains the v1alpha1 group Sample resources of the Openshift provider.
// +kubebuilder:object:generate=true
// +groupName=containers.azure.crossplane.io
// +versionName=v1alpha1
package v1alpha1

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

// Package type metadata.
const (
Group = "containers.azure.crossplane.io"
Version = "v1alpha1"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: Group, Version: Version}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
)
137 changes: 137 additions & 0 deletions apis/containers/v1alpha1/openshift_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Copyright 2022 The Crossplane 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 v1alpha1

import (
"reflect"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// OpenshiftParameters are the configurable fields of a Openshift.
type OpenshiftParameters struct {
ResourceGroupName string `json:"resourceGroupName,omitempty"`
ResourceGroupNameRef *xpv1.Reference `json:"resourceGroupNameRef,omitempty"`
ResourceGroupNameSelector *xpv1.Selector `json:"resourceGroupNameSelector,omitempty"`
Location string `json:"location,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
ClusterProfile `json:"clusterProfile,omitempty"`
ServicePrincipalProfile `json:"servicePrincipalProfile,omitempty"`
NetworkProfile `json:"networkProfile,omitempty"`
WorkerProfile `json:"workerProfile,omitempty"`
MasterProfile `json:"masterProfile,omitempty"`
}

type ClusterProfile struct {
PullSecretRef *xpv1.SecretKeySelector `json:"pullSecretRef,omitempty"`
PullSecret string `json:"pullSecret,omitempty"`
Domain string `json:"domain,omitempty"`
Version string `json:"version,omitempty"`
ResourceGroupID string `json:"resourceGroupId,omitempty"`
}

type ServicePrincipalProfile struct {
AzureRedHatOpenShiftRPPrincipalIDRef *xpv1.SecretKeySelector `json:"azureRedHatOpenShiftRPPrincipalIDRef,omitempty"`
AzureRedHatOpenShiftRPPrincipalID string `json:"azureRedHatOpenShiftRPPrincipalID,omitempty"`
PrincipalID string `json:"servicePrincipalId,omitempty"`
PrincipalIDRef *xpv1.SecretKeySelector `json:"servicePrincipalIdRef,omitempty"`
ClientIDRef *xpv1.SecretKeySelector `json:"clientIdRef,omitempty"`
ClientSecretRef *xpv1.SecretKeySelector `json:"clientSecretRef,omitempty"`
ClientID string `json:"clientId,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
}

type NetworkProfile struct {
PodCidr string `json:"podCidr,omitempty"`
ServiceCidr string `json:"serviceCidr,omitempty"`
}

type MasterProfile struct {
VMSize string `json:"vmSize,omitempty"`
SubnetIDRef *xpv1.Reference `json:"subnetIDRef,omitempty"`
SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"`
SubnetID string `json:"subnetID,omitempty"`
}

type WorkerProfile struct {
VMSize string `json:"vmSize,omitempty"`
DiskSizeGB int `json:"diskSizeGB,omitempty"`
SubnetIDRef *xpv1.Reference `json:"subnetIDRef,omitempty"`
SubnetIDSelector *xpv1.Selector `json:"subnetIDSelector,omitempty"`
SubnetID string `json:"subnetID,omitempty"`
Count int `json:"count,omitempty"`
}

// OpenshiftObservation are the observable fields of a Openshift.
type OpenshiftObservation struct {
ProvisioningState string `json:"provisioningState,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}

// A OpenshiftSpec defines the desired state of a Openshift.
type OpenshiftSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider OpenshiftParameters `json:"forProvider"`
}

// A OpenshiftStatus represents the observed state of a Openshift.
type OpenshiftStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider OpenshiftObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// A Openshift is an example API type.
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,openshift}
type Openshift struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec OpenshiftSpec `json:"spec"`
Status OpenshiftStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

// Openshift type metadata.
var (
OpenshiftKind = reflect.TypeOf(Openshift{}).Name()
OpenshiftGroupKind = schema.GroupKind{Group: Group, Kind: OpenshiftKind}.String()
OpenshiftKindAPIVersion = OpenshiftKind + "." + SchemeGroupVersion.String()
OpenshiftGroupVersionKind = SchemeGroupVersion.WithKind(OpenshiftKind)
)

func init() {
SchemeBuilder.Register(&Openshift{}, &OpenshiftList{})
}
74 changes: 74 additions & 0 deletions apis/containers/v1alpha1/referencers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
Copyright 2019 The Crossplane 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 v1alpha1

import (
"context"

networkv1alpha3 "github.com/crossplane-contrib/provider-azure/apis/network/v1alpha3"
"github.com/crossplane-contrib/provider-azure/apis/v1alpha3"
"github.com/crossplane/crossplane-runtime/pkg/reference"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (mg *Openshift) ResolveReferences(ctx context.Context, c client.Reader) error {
r := reference.NewAPIResolver(c, mg)

// Resolve spec.forProvider.resourceGroupName
rsp, err := r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ForProvider.ResourceGroupName,
Reference: mg.Spec.ForProvider.ResourceGroupNameRef,
Selector: mg.Spec.ForProvider.ResourceGroupNameSelector,
To: reference.To{Managed: &v1alpha3.ResourceGroup{}, List: &v1alpha3.ResourceGroupList{}},
Extract: reference.ExternalName(),
})
if err != nil {
return errors.Wrap(err, "spec.forProvider.resourceGroupName")
}

mg.Spec.ForProvider.ResourceGroupName = rsp.ResolvedValue
mg.Spec.ForProvider.ResourceGroupNameRef = rsp.ResolvedReference

rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ForProvider.MasterProfile.SubnetID,
Reference: mg.Spec.ForProvider.MasterProfile.SubnetIDRef,
Selector: mg.Spec.ForProvider.MasterProfile.SubnetIDSelector,
To: reference.To{Managed: &networkv1alpha3.Subnet{}, List: &networkv1alpha3.SubnetList{}},
Extract: networkv1alpha3.SubnetID(),
})
if err != nil {
return errors.Wrap(err, "spec.subnetID")
}
mg.Spec.ForProvider.MasterProfile.SubnetID = rsp.ResolvedValue
mg.Spec.ForProvider.MasterProfile.SubnetIDRef = rsp.ResolvedReference

rsp, err = r.Resolve(ctx, reference.ResolutionRequest{
CurrentValue: mg.Spec.ForProvider.WorkerProfile.SubnetID,
Reference: mg.Spec.ForProvider.WorkerProfile.SubnetIDRef,
Selector: mg.Spec.ForProvider.WorkerProfile.SubnetIDSelector,
To: reference.To{Managed: &networkv1alpha3.Subnet{}, List: &networkv1alpha3.SubnetList{}},
Extract: networkv1alpha3.SubnetID(),
})
if err != nil {
return errors.Wrap(err, "spec.subnetID")
}
mg.Spec.ForProvider.WorkerProfile.SubnetID = rsp.ResolvedValue
mg.Spec.ForProvider.WorkerProfile.SubnetIDRef = rsp.ResolvedReference

return nil
}
Loading