Merge "Fix manifests generation"

This commit is contained in:
Zuul 2021-11-12 16:33:12 +00:00 committed by Gerrit Code Review
commit e93145a59f
22 changed files with 115 additions and 107 deletions

View File

@ -391,7 +391,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
@ -401,4 +401,4 @@ endif
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=manifests/function/airshipctl-schemas
find manifests/function/airshipctl-schemas/ -type f -not -name 'kustomization.yaml' -delete && $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=manifests/function/airshipctl-schemas

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: baremetalmanagers.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: bootconfigurations.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: clusterctls.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: clustermaps.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: genericcontainers.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: hosts.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: isoconfigurations.airshipit.org
spec:
@ -39,40 +39,29 @@ spec:
description: Cloud Init network config will be retrieved from the
doc matching this object
properties:
selector:
description: Selector specifies a set of resources. Any resource
that matches intersection of all conditions is included in this
set.
properties:
annotationSelector:
description: AnnotationSelector is a string that follows the
label selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource annotations.
type: string
group:
type: string
isClusterScoped:
description: isClusterScoped is true if the object is known,
per the openapi data in use, to be cluster scoped, and false
otherwise.
type: boolean
kind:
type: string
labelSelector:
description: LabelSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource labels.
type: string
name:
description: Name of the resource.
type: string
namespace:
description: Namespace the resource belongs to, if it can
belong to a namespace.
type: string
version:
type: string
type: object
annotationSelector:
description: AnnotationSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource annotations.
type: string
group:
type: string
kind:
type: string
labelSelector:
description: LabelSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource labels.
type: string
name:
description: Name of the resource.
type: string
namespace:
description: Namespace the resource belongs to, if it can belong
to a namespace.
type: string
version:
type: string
type: object
outputFileName:
description: File name to use for the output image that will be written
@ -86,40 +75,29 @@ spec:
description: Cloud Init user data will be retrieved from the doc matching
this object
properties:
selector:
description: Selector specifies a set of resources. Any resource
that matches intersection of all conditions is included in this
set.
properties:
annotationSelector:
description: AnnotationSelector is a string that follows the
label selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource annotations.
type: string
group:
type: string
isClusterScoped:
description: isClusterScoped is true if the object is known,
per the openapi data in use, to be cluster scoped, and false
otherwise.
type: boolean
kind:
type: string
labelSelector:
description: LabelSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource labels.
type: string
name:
description: Name of the resource.
type: string
namespace:
description: Namespace the resource belongs to, if it can
belong to a namespace.
type: string
version:
type: string
type: object
annotationSelector:
description: AnnotationSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource annotations.
type: string
group:
type: string
kind:
type: string
labelSelector:
description: LabelSelector is a string that follows the label
selection expression https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
It matches with the resource labels.
type: string
name:
description: Name of the resource.
type: string
namespace:
description: Namespace the resource belongs to, if it can belong
to a namespace.
type: string
version:
type: string
type: object
type: object
container:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: kubeconfigs.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: kubernetesapplies.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: manifestmetadata.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: networkcatalogues.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: phaseplans.airshipit.org
spec:
@ -67,7 +67,7 @@ spec:
type: array
kubernetesVersion:
description: KubernetesVersion is the version of Kubernetes to validate
against (default "1.21.2").
against (default "1.18.6").
type: string
schemaLocation:
description: SchemaLocation is the base URL from which to search for

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: phases.airshipit.org
spec:
@ -116,7 +116,7 @@ spec:
type: array
kubernetesVersion:
description: KubernetesVersion is the version of Kubernetes to
validate against (default "1.21.2").
validate against (default "1.18.6").
type: string
schemaLocation:
description: SchemaLocation is the base URL from which to search

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: replacementtransformers.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: templaters.airshipit.org
spec:

View File

@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.1
controller-gen.kubebuilder.io/version: v0.6.2
creationTimestamp: null
name: versionscatalogues.airshipit.org
spec:

View File

@ -16,8 +16,6 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"opendev.org/airship/airshipctl/pkg/document"
)
// IsoContainer structure contains parameters related to Docker runtime, used for building image
@ -33,11 +31,11 @@ type IsoContainer struct {
// Isogen structure defines document selection criteria for cloud-init metadata
type Isogen struct {
// Cloud Init user data will be retrieved from the doc matching this object
UserDataSelector document.Selector `json:"userDataSelector,omitempty"`
UserDataSelector Selector `json:"userDataSelector,omitempty"`
// Cloud init user data will be retrieved from this document key
UserDataKey string `json:"userDataKey,omitempty"`
// Cloud Init network config will be retrieved from the doc matching this object
NetworkConfigSelector document.Selector `json:"networkConfigSelector,omitempty"`
NetworkConfigSelector Selector `json:"networkConfigSelector,omitempty"`
// Cloud init network config will be retrieved from this document key
NetworkConfigKey string `json:"networkConfigKey,omitempty"`
// File name to use for the output image that will be written to the container volume root

View File

@ -1,4 +1,3 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*

View File

@ -15,6 +15,7 @@
package cloudinit
import (
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
"opendev.org/airship/airshipctl/pkg/document"
)
@ -27,13 +28,15 @@ const (
// ephemeral node.
func GetCloudData(
docBundle document.Bundle,
userDataSelector document.Selector,
userDataSelector v1alpha1.Selector,
userDataKey string,
networkConfigSelector document.Selector,
networkConfigSelector v1alpha1.Selector,
networkConfigKey string,
) (userData []byte, netConf []byte, err error) {
uDataSel := document.NewSelectorFromV1Alpha1(userDataSelector)
nwDataSel := document.NewSelectorFromV1Alpha1(networkConfigSelector)
userDataSelectorFinal, userDataKeyFinal := applyDefaultsAndGetData(
userDataSelector,
uDataSel,
document.SecretKind,
document.EphemeralUserDataSelector,
userDataKey,
@ -45,7 +48,7 @@ func GetCloudData(
}
netConfSelectorFinal, netConfKeyFinal := applyDefaultsAndGetData(
networkConfigSelector,
nwDataSel,
document.BareMetalHostKind,
document.EphemeralHostSelector,
networkConfigKey,

View File

@ -18,29 +18,40 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
"opendev.org/airship/airshipctl/pkg/document"
)
type selectors struct {
userDataSelector document.Selector
userDataSelector v1alpha1.Selector
userDataKey string
networkConfigSelector document.Selector
networkConfigSelector v1alpha1.Selector
networkConfigKey string
}
var (
emptySelectors = selectors{
userDataSelector: document.NewSelector(),
networkConfigSelector: document.NewSelector(),
userDataSelector: v1alpha1.Selector{},
networkConfigSelector: v1alpha1.Selector{},
}
validSelectors = selectors{
userDataSelector: document.NewSelector().
ByKind(secret).
ByLabel(ephUser),
userDataSelector: v1alpha1.Selector{
ResID: v1alpha1.ResID{
Gvk: v1alpha1.Gvk{
Kind: secret,
},
},
LabelSelector: ephUser,
},
userDataKey: defaultUserDataKey,
networkConfigSelector: document.NewSelector().
ByKind(bmh).
ByLabel(ephNode),
networkConfigSelector: v1alpha1.Selector{
ResID: v1alpha1.ResID{
Gvk: v1alpha1.Gvk{
Kind: bmh,
},
},
LabelSelector: ephNode,
},
networkConfigKey: defaultNetworkConfigKey,
}
)

View File

@ -23,6 +23,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
"opendev.org/airship/airshipctl/pkg/api/v1alpha1"
)
// Selector provides abstraction layer in front of kustomize selector
@ -35,6 +37,23 @@ func NewSelector() Selector {
return Selector{}
}
// NewSelectorFromV1Alpha1 generates selector object from v1alpha1 analog
func NewSelectorFromV1Alpha1(selector v1alpha1.Selector) Selector {
return Selector{types.Selector{
ResId: resid.ResId{
Gvk: resid.Gvk{
Group: selector.Gvk.Group,
Version: selector.Gvk.Version,
Kind: selector.Gvk.Kind,
},
Name: selector.Name,
Namespace: selector.Namespace,
},
AnnotationSelector: selector.AnnotationSelector,
LabelSelector: selector.LabelSelector,
}}
}
// Following set of functions allows to build selector object
// by name, gvk, label selector and annotation selector