Skip to content

Commit

Permalink
added CRD example
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykorwat committed Sep 12, 2024
1 parent 511ddda commit 95ebe75
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
7 changes: 7 additions & 0 deletions artifacts/aws-test/s3-bucket.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: aws.hykube.io/v1
kind: aws-s3-bucket
metadata:
name: test-bucket
spec:
bucket: "my-s3-bucket"
acl: "private"
15 changes: 11 additions & 4 deletions docs/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,33 @@ You should now be able to create the resource type `Provider` which is the resou

```shell
kubectl create -f artifacts/providers/aws.yaml
# outputs provider "aws" created
# provider "aws" created
```

You can then get this resource by running:

```shell
kubectl get provider aws -o custom-columns=Name:.metadata.name,status:.status,CreatedAt:.metadata.creationTimestamp
#outputs
# Name status CreatedAt
# aws adding CRDs 2024-09-12T09:15:29Z
```

After the provider is initialized, you should see status `ready`:
After the provider is initialized and all ~1500 CRDs are added (can take a while), you should see status `ready`:
```shell
kubectl get provider aws -o custom-columns=Name:.metadata.name,status:.status,CreatedAt:.metadata.creationTimestamp
#outputs
# Name status CreatedAt
# aws ready 2024-09-12T09:15:29Z
```

## Deploy locally resources

Once the provider is ready, you can add a test AWS S3 bucket:

```shell
kubectl create -f artifacts/aws-test/s3-bucket.yaml
# aws-s3-bucket.aws.hykube.io/test-bucket created
```

## Local binary run

Generate certificates for CA and test user `development` in the superuser group `system:masters` for local testing:
Expand Down
26 changes: 17 additions & 9 deletions pkg/registry/hykube/provider/hashicorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func (h *hashicorpProvider) addCDRs(schemaResponse *providers.GetSchemaResponse,

crdClient, err := crd_clientset.NewForConfig(config)
CRDGroup := provider.Name + ".hykube.io"
CRDVersion := "v1alpha1"
CRDVersion := "v1"
trueVal := true

if err != nil {
return err
Expand Down Expand Up @@ -299,9 +300,11 @@ func (h *hashicorpProvider) addCDRs(schemaResponse *providers.GetSchemaResponse,
// TODO: handle nested array types e.g. E0912 13:04:45.166040 1 hashicorp.go:364] "cannot add resource type:aws_cloudfront_distribution" err="CustomResourceDefinition.apiextensions.k8s.io \"aws-cloudfront-distributions.aws.hykube.io\" is invalid: [spec.validation.openAPIV3Schema.properties[trusted_key_groups].items.properties[items].items: Required value: must be specified, spec.validation.openAPIV3Schema.properties[trusted_signers].items.properties[items].items: Required value: must be specified]"
Items: &apiextensionv1.JSONSchemaPropsOrArray{
Schema: &apiextensionv1.JSONSchemaProps{
Type: attrItemType,
Type: attrItemType,
XPreserveUnknownFields: &trueVal,
},
},
XPreserveUnknownFields: &trueVal,
}
} else {
// TODO handle array of arrays...
Expand All @@ -310,24 +313,27 @@ func (h *hashicorpProvider) addCDRs(schemaResponse *providers.GetSchemaResponse,
attrItemPropertyType := h.attributeType(&attrItemPropV)
// TODO: address nested array types
attrItemProperties[attrItemPropK] = apiextensionv1.JSONSchemaProps{
Type: attrItemPropertyType,
Type: attrItemPropertyType,
XPreserveUnknownFields: &trueVal,
}
}

properties[attrK] = apiextensionv1.JSONSchemaProps{
Type: attributeType,
Items: &apiextensionv1.JSONSchemaPropsOrArray{
Schema: &apiextensionv1.JSONSchemaProps{
Type: "object",
Properties: attrItemProperties,
Type: "object",
Properties: attrItemProperties,
XPreserveUnknownFields: &trueVal,
},
},
}
}
} else {
// TODO: define fields for object type
properties[attrK] = apiextensionv1.JSONSchemaProps{
Type: attributeType,
Type: attributeType,
XPreserveUnknownFields: &trueVal,
}
}
}
Expand All @@ -340,11 +346,13 @@ func (h *hashicorpProvider) addCDRs(schemaResponse *providers.GetSchemaResponse,
{
Name: CRDVersion,
Storage: true,
Served: true,
Schema: &apiextensionv1.CustomResourceValidation{
OpenAPIV3Schema: &apiextensionv1.JSONSchemaProps{
Type: "object",
Required: requiredFields,
Properties: properties,
Type: "object",
Required: requiredFields,
Properties: properties,
XPreserveUnknownFields: &trueVal,
},
},
},
Expand Down

0 comments on commit 95ebe75

Please sign in to comment.