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

Support of CRD #11

Closed
Erouan50 opened this issue Jan 18, 2019 · 24 comments
Closed

Support of CRD #11

Erouan50 opened this issue Jan 18, 2019 · 24 comments

Comments

@Erouan50
Copy link

Erouan50 commented Jan 18, 2019

Hi,

I tried to create a backend config with the provider, but it seems not to support custom resource. Do you plan to add this support?

Thanks!

resource "k8sraw_yaml" "backend_config" {
  yaml_body = <<YAML
apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
  name: my-backend-config
spec:
  cdn:
    enabled: true
    cachePolicy:
      includeHost: true
      includeProtocol: true
      includeQueryString: false

YAML
}

Output:

k8sraw_yaml.backend_config: Creating...
  live_resource_version: "" => "<computed>"
  live_uid:              "" => "<computed>"
  live_yaml_incluster:   "" => "<computed>"
  resource_version:      "" => "<computed>"
  uid:                   "" => "<computed>"
  yaml_body:             "" => "apiVersion: cloud.google.com/v1beta1\nkind: BackendConfig\nmetadata:\n  name: my-backend-config\nspec:\n  cdn:\n    enabled: true\n    cachePolicy:\n      includeHost: true\n      includeProtocol: true\n      includeQueryString: false\n\n"
  yaml_incluster:        "" => "<computed>"

Error: Error applying plan:

1 error(s) occurred:

* k8sraw_yaml.backend_config: 1 error(s) occurred:

* k8sraw_yaml.backend_config: failed to create kubernetes rest client for resource: no kind "BackendConfig" is registered for version "cloud.google.com/v1beta1"
@lawrencegripper
Copy link
Owner

Thanks, this is a use case I want to be able to support.

I've got an integration test up and running in #14 which recreates the problem and I'll look at fixing it up.

Any help or thoughts welcome, it looks like this error is raised by this line using the universal decoder. Need to work out why it's not so universal!

@mikemorris
Copy link

Just wanted to bump that adding this functionality would be quite useful, I hit this following the cert-manager tutorial in https://itnext.io/automated-tls-with-cert-manager-and-letsencrypt-for-kubernetes-7daaa5e0cae4 (after discovering the lack of a generic resource in the official Kubernetes provider), when attempting to apply the following YAML:

apiVersion: certmanager.k8s.io/v1alpha1
kind: ClusterIssuer
metadata:
  name: letsencrypt-staging
spec:
  acme:
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    email: foo@example.com
    privateKeySecretRef:
      name: letsencrypt-staging
    http01: {}

Applying manually with kubectl -f works fine, but as a k8sraw_yaml Terraform resource, yielded the following error:

* k8sraw_yaml.letsencrypt-cluster-issuer: failed to create kubernetes rest client for resource: no kind "ClusterIssuer" is registered for version "certmanager.k8s.io/v1alpha1" in scheme "k8s.io/client-go/kubernetes/scheme/register.go:61"

@lawrencegripper
Copy link
Owner

I made a bit of progress here working around the issues without doing any reading about the structure of the k8s client libraries handling of CRDs.

#14

While my workaround's got things created I then have trouble reading the objects back correctly.

After doing some more reading it looks like I need to move the code over to using the dynamic client as shown here https://stackoverflow.com/a/47139247/3437018

@davisford
Copy link

Eagerly looking forward to this -- I also just tried and got bit by a CRD yaml definition.

@lawrencegripper
Copy link
Owner

I've had a bit of time on a few flights recently to try and complete this migration to the dynamic client. There is now an EXPERIMENTAL/PRE-RELEASE build for testing here https://github.com/lawrencegripper/terraform-provider-kubernetes-yaml/releases/tag/v0.2.45-crdrc1

Currently, due to some knock on effects of the changes my test suite isn't working so do please be careful when testing this and avoid anything production shaped.

@davisford
Copy link

Hi @lawrencegripper -- thanks for that. It appears to be working for me. I'm testing a CRD for CouchbaseCluster and I'm able to do it with the embedded yaml now. Hoping you get the tests sorted out and can release this as a new version!

@lawrencegripper
Copy link
Owner

Awesome 👍 Very happy a couple of late nights and airplane journeys paid off!

@lawrencegripper
Copy link
Owner

@davisford quick heads up that this has a couple of bugs that I'm working through as part of tests. Primarily if the "RevisionVersion" changes TF apply will try and re-deploy the CRD.

The problem is that updates to the CRD's status fields will cause this to occur. Previously I had some nice reflection logic in place to skip these fields from the comparison but the change to the dynamic client has caused some issues here so use with caution for the moment.

@lawrencegripper
Copy link
Owner

Finished this up now, no guarentee's but new build should be live shortly for testing.

@davisford
Copy link

Awesome thank you trying release v0.1.83 now

@davisford
Copy link

@lawrencegripper I'm getting this error now with the latest release, whereas it used to to work when I was on the previously cited branch:

1 error(s) occurred:

* module.cb-cluster.k8sraw_yaml.cb-server-cluster: 1 error(s) occurred:

* k8sraw_yaml.cb-server-cluster: failed to create kubernetes rest client for resource: resource provided in yaml isn't valid for cluster, check the APIVersion and Kind fields are valid

I don't think anything has changed with the version, etc. for the YAML. This is a CRD that is defined here, and this is my terraform file:

resource "k8sraw_yaml" "cb-server-cluster" {
    yaml_body = <<YAML
apiVersion: couchbase.com/v1
kind: CouchbaseCluster
metadata:
  name: ${var.cb-cluster-name}
spec:
  baseImage: ${var.cb-cluster-image}
  version: ${var.cb-cluster-image-version}
  authSecret: ${var.cb-operator-secret-name}
  exposeAdminConsole: true
  adminConsoleServices:
    - data
  cluster:
    dataServiceMemoryQuota: 256
    indexServiceMemoryQuota: 256
    searchServiceMemoryQuota: 256
    eventingServiceMemoryQuota: 256
    analyticsServiceMemoryQuota: 1024
    indexStorageSetting: memory_optimized
    autoFailoverTimeout: 120
    autoFailoverMaxCount: 3
    autoFailoverOnDataDiskIssues: true
    autoFailoverOnDataDiskIssuesTimePeriod: 120
    autoFailoverServerGroup: false
  buckets:
    - name: default
      type: couchbase
      memoryQuota: 128
      replicas: 1
      ioPriority: high
      evictionPolicy: fullEviction
      conflictResolution: seqno
      enableFlush: true
      enableIndexReplica: false
    - name: test
      type: couchbase
      memoryQuota: 128
      replicas: 1
      ioPriority: high
      evictionPolicy: fullEviction
      conflictResolution: seqno
      enableFlush: true
      enableIndexReplica: false
  servers:
    - size: 3
      name: all_services
      services:
        - data
        - index
        - query
        - search
        - eventing
        - analytics

    YAML
}

Maybe I'll try rolling back to the old one I was using and see if that fixes the issue.

@davisford
Copy link

The CRD is defined in my cluster:

ml-dford:localhost dford$ kc describe crd couchbaseclusters.couchbase.com 
Name:         couchbaseclusters.couchbase.com
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  apiextensions.k8s.io/v1beta1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2019-04-12T18:09:26Z
  Generation:          1
  Resource Version:    987
  Self Link:           /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/couchbaseclusters.couchbase.com
  UID:                 1bdf7bf7-5d4e-11e9-987c-000c290425d0
Spec:
  Conversion:
    Strategy:  None
  Group:       couchbase.com
  Names:
    Kind:       CouchbaseCluster
    List Kind:  CouchbaseClusterList
    Plural:     couchbaseclusters
    Short Names:
      couchbase
      cbc
    Singular:  couchbasecluster
  Scope:       Namespaced
  Validation:
    Open APIV 3 Schema:
      Properties:
        Spec:
          Properties:
            Admin Console Services:
              Items:
                Enum:
                  data
                  index
                  query
                  search
                  eventing
                  analytics
                Type:  string
              Type:    array
            Anti Affinity:
              Type:  boolean
            Auth Secret:
              Min Length:  1
              Type:        string
            Base Image:
              Type:  string
            Buckets:
              Items:
                Properties:
                  Conflict Resolution:
                    Enum:
                      seqno
                      lww
                    Type:  string
                  Enable Flush:
                    Type:  boolean
                  Enable Index Replica:
                    Type:  boolean
                  Eviction Policy:
                    Enum:
                      valueOnly
                      fullEviction
                      noEviction
                      nruEviction
                    Type:  string
                  Io Priority:
                    Enum:
                      high
                      low
                    Type:  string
                  Memory Quota:
                    Minimum:  100
                    Type:     integer
                  Name:
                    Pattern:  ^[a-zA-Z0-9._\-%]*$
                    Type:     string
                  Replicas:
                    Maximum:  3
                    Minimum:  0
                    Type:     integer
                  Type:
                    Enum:
                      couchbase
                      ephemeral
                      memcached
                    Type:  string
                Required:
                  name
                  type
                  memoryQuota
                Type:  object
              Type:    array
            Cluster:
              Properties:
                Analytics Service Memory Quota:
                  Minimum:  1024
                  Type:     integer
                Auto Failover Max Count:
                  Maximum:  3
                  Minimum:  1
                  Type:     integer
                Auto Failover On Data Disk Issues:
                  Type:  boolean
                Auto Failover On Data Disk Issues Time Period:
                  Maximum:  3600
                  Minimum:  5
                  Type:     integer
                Auto Failover Server Group:
                  Type:  boolean
                Auto Failover Timeout:
                  Maximum:  3600
                  Minimum:  5
                  Type:     integer
                Cluster Name:
                  Type:  string
                Data Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Eventing Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Index Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Index Storage Setting:
                  Enum:
                    plasma
                    memory_optimized
                  Type:  string
                Search Service Memory Quota:
                  Minimum:  256
                  Type:     integer
              Required:
                dataServiceMemoryQuota
                indexServiceMemoryQuota
                searchServiceMemoryQuota
                eventingServiceMemoryQuota
                analyticsServiceMemoryQuota
                indexStorageSetting
                autoFailoverTimeout
                autoFailoverMaxCount
              Type:  object
            Disable Bucket Management:
              Type:  boolean
            Expose Admin Console:
              Type:  boolean
            Exposed Features:
              Items:
                Enum:
                  admin
                  xdcr
                  client
                Type:  string
              Type:    array
            Log Retention Count:
              Minimum:  0
              Type:     integer
            Log Retention Time:
              Pattern:  ^\d+(ns|us|ms|s|m|h)$
              Type:     string
            Paused:
              Type:  boolean
            Server Groups:
              Items:
                Type:  string
              Type:    array
            Servers:
              Items:
                Properties:
                  Name:
                    Min Length:  1
                    Pattern:     ^[-_a-zA-Z0-9]+$
                    Type:        string
                  Pod:
                    Properties:
                      Automount Service Account Token:
                        Type:  boolean
                      Couchbase Env:
                        Items:
                          Properties:
                            Name:
                              Type:  string
                            Value:
                              Type:  string
                          Type:      object
                        Type:        array
                      Labels:
                        Type:  object
                      Node Selector:
                        Type:  object
                      Resources:
                        Properties:
                          Limits:
                            Properties:
                              Cpu:
                                Type:  string
                              Memory:
                                Type:  string
                              Storage:
                                Type:  string
                            Type:      object
                          Requests:
                            Properties:
                              Cpu:
                                Type:  string
                              Memory:
                                Type:  string
                              Storage:
                                Type:  string
                            Type:      object
                        Type:          object
                      Tolerations:
                        Items:
                          Properties:
                            Effect:
                              Type:  string
                            Key:
                              Type:  string
                            Operator:
                              Type:  string
                            Toleration Seconds:
                              Type:  integer
                            Value:
                              Type:  string
                          Required:
                            key
                            operator
                            value
                            effect
                          Type:  object
                        Type:    array
                      Volume Mounts:
                        Properties:
                          Analytics:
                            Items:
                              Type:  string
                            Type:    array
                          Data:
                            Type:  string
                          Default:
                            Type:  string
                          Index:
                            Type:  string
                          Logs:
                            Type:  string
                        Type:      object
                    Type:          object
                  Server Groups:
                    Items:
                      Type:  string
                    Type:    array
                  Services:
                    Items:
                      Enum:
                        data
                        index
                        query
                        search
                        eventing
                        analytics
                      Type:      string
                    Min Length:  1
                    Type:        array
                  Size:
                    Minimum:  1
                    Type:     integer
                Required:
                  size
                  name
                  services
                Type:      object
              Min Length:  1
              Type:        array
            Software Update Notifications:
              Type:  boolean
            Tls:
              Properties:
                Static:
                  Properties:
                    Member:
                      Properties:
                        Server Secret:
                          Type:  string
                      Type:      object
                    Operator Secret:
                      Type:  string
                  Type:      object
              Type:          object
            Version:
              Pattern:  ^([\w\d]+-)?\d+\.\d+.\d+(-[\w\d]+)?$
              Type:     string
            Volume Claim Templates:
              Items:
                Properties:
                  Metadata:
                    Properties:
                      Name:
                        Type:  string
                    Required:
                      name
                    Type:  object
                  Spec:
                    Properties:
                      Resources:
                        Properties:
                          Limits:
                            Properties:
                              Storage:
                                Type:  string
                            Required:
                              storage
                            Type:  object
                          Requests:
                            Properties:
                              Storage:
                                Type:  string
                            Required:
                              storage
                            Type:  object
                        Type:      object
                      Storage Class Name:
                        Type:  string
                    Required:
                      resources
                      storageClassName
                    Type:  object
                Required:
                  metadata
                  spec
                Type:  object
              Type:    array
          Required:
            baseImage
            version
            authSecret
            cluster
            servers
  Version:  v1
  Versions:
    Name:     v1
    Served:   true
    Storage:  true
Status:
  Accepted Names:
    Kind:       CouchbaseCluster
    List Kind:  CouchbaseClusterList
    Plural:     couchbaseclusters
    Short Names:
      couchbase
      cbc
    Singular:  couchbasecluster
  Conditions:
    Last Transition Time:  2019-04-12T18:09:26Z
    Message:               no conflicts found
    Reason:                NoConflicts
    Status:                True
    Type:                  NamesAccepted
    Last Transition Time:  <nil>
    Message:               the initial names have been accepted
    Reason:                InitialNamesAccepted
    Status:                True
    Type:                  Established
  Stored Versions:
    v1
Events:  <none>

@davisford
Copy link

@lawrencegripper can confirm, when I swap back in v0.2.45-crdrc1 it works for me again.

what changed?

@lawrencegripper
Copy link
Owner

lawrencegripper commented Apr 15, 2019

Interesting, I'll add this one into the integration tests when I get a moment (bit back to back at the moment) and try and track down the cause.

Off the top of my head the only major changes should have been in the testing code. I'd expect to see that error if the CRD wasn't defined in the cluster and we attempted to create an instance of it - must be something up that I've nudged when making changes for the testing.

@lawrencegripper
Copy link
Owner

lawrencegripper commented Apr 15, 2019

@davisford could you send me the output of kc describe crd couchbaseclusters.couchbase.com but with -o yaml so I can add a test which re-creates the CRD definition during integration testing and then attempt to an instance of it.

@davisford
Copy link

@lawrencegripper I will get that output, but I just discovered something else. So, I'm running with the older v0.2.45-crdrc1 and all was well. But then I wanted to add a k8s feature gate that was not enabled. So I had to destroy my current minikube and spin up a new one. After I did that, I got the same error. So, I think it is somehow related to the apiVersion like the error says, b/c I think when I spawned a new minikube it grabbed a newer k8s deployment. I'm going to try again now with your latest and report back.

@davisford
Copy link

$ kc describe crd 
Name:         couchbaseclusters.couchbase.com
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  apiextensions.k8s.io/v1beta1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2019-04-15T21:00:28Z
  Generation:          1
  Resource Version:    1019
  Self Link:           /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/couchbaseclusters.couchbase.com
  UID:                 7fa36465-5fc1-11e9-868c-6677e3d2572b
Spec:
  Conversion:
    Strategy:  None
  Group:       couchbase.com
  Names:
    Kind:       CouchbaseCluster
    List Kind:  CouchbaseClusterList
    Plural:     couchbaseclusters
    Short Names:
      couchbase
      cbc
    Singular:  couchbasecluster
  Scope:       Namespaced
  Validation:
    Open APIV 3 Schema:
      Properties:
        Spec:
          Properties:
            Admin Console Services:
              Items:
                Enum:
                  data
                  index
                  query
                  search
                  eventing
                  analytics
                Type:  string
              Type:    array
            Anti Affinity:
              Type:  boolean
            Auth Secret:
              Min Length:  1
              Type:        string
            Base Image:
              Type:  string
            Buckets:
              Items:
                Properties:
                  Conflict Resolution:
                    Enum:
                      seqno
                      lww
                    Type:  string
                  Enable Flush:
                    Type:  boolean
                  Enable Index Replica:
                    Type:  boolean
                  Eviction Policy:
                    Enum:
                      valueOnly
                      fullEviction
                      noEviction
                      nruEviction
                    Type:  string
                  Io Priority:
                    Enum:
                      high
                      low
                    Type:  string
                  Memory Quota:
                    Minimum:  100
                    Type:     integer
                  Name:
                    Pattern:  ^[a-zA-Z0-9._\-%]*$
                    Type:     string
                  Replicas:
                    Maximum:  3
                    Minimum:  0
                    Type:     integer
                  Type:
                    Enum:
                      couchbase
                      ephemeral
                      memcached
                    Type:  string
                Required:
                  name
                  type
                  memoryQuota
                Type:  object
              Type:    array
            Cluster:
              Properties:
                Analytics Service Memory Quota:
                  Minimum:  1024
                  Type:     integer
                Auto Failover Max Count:
                  Maximum:  3
                  Minimum:  1
                  Type:     integer
                Auto Failover On Data Disk Issues:
                  Type:  boolean
                Auto Failover On Data Disk Issues Time Period:
                  Maximum:  3600
                  Minimum:  5
                  Type:     integer
                Auto Failover Server Group:
                  Type:  boolean
                Auto Failover Timeout:
                  Maximum:  3600
                  Minimum:  5
                  Type:     integer
                Cluster Name:
                  Type:  string
                Data Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Eventing Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Index Service Memory Quota:
                  Minimum:  256
                  Type:     integer
                Index Storage Setting:
                  Enum:
                    plasma
                    memory_optimized
                  Type:  string
                Search Service Memory Quota:
                  Minimum:  256
                  Type:     integer
              Required:
                dataServiceMemoryQuota
                indexServiceMemoryQuota
                searchServiceMemoryQuota
                eventingServiceMemoryQuota
                analyticsServiceMemoryQuota
                indexStorageSetting
                autoFailoverTimeout
                autoFailoverMaxCount
              Type:  object
            Disable Bucket Management:
              Type:  boolean
            Expose Admin Console:
              Type:  boolean
            Exposed Features:
              Items:
                Enum:
                  admin
                  xdcr
                  client
                Type:  string
              Type:    array
            Log Retention Count:
              Minimum:  0
              Type:     integer
            Log Retention Time:
              Pattern:  ^\d+(ns|us|ms|s|m|h)$
              Type:     string
            Paused:
              Type:  boolean
            Server Groups:
              Items:
                Type:  string
              Type:    array
            Servers:
              Items:
                Properties:
                  Name:
                    Min Length:  1
                    Pattern:     ^[-_a-zA-Z0-9]+$
                    Type:        string
                  Pod:
                    Properties:
                      Automount Service Account Token:
                        Type:  boolean
                      Couchbase Env:
                        Items:
                          Properties:
                            Name:
                              Type:  string
                            Value:
                              Type:  string
                          Type:      object
                        Type:        array
                      Labels:
                        Type:  object
                      Node Selector:
                        Type:  object
                      Resources:
                        Properties:
                          Limits:
                            Properties:
                              Cpu:
                                Type:  string
                              Memory:
                                Type:  string
                              Storage:
                                Type:  string
                            Type:      object
                          Requests:
                            Properties:
                              Cpu:
                                Type:  string
                              Memory:
                                Type:  string
                              Storage:
                                Type:  string
                            Type:      object
                        Type:          object
                      Tolerations:
                        Items:
                          Properties:
                            Effect:
                              Type:  string
                            Key:
                              Type:  string
                            Operator:
                              Type:  string
                            Toleration Seconds:
                              Type:  integer
                            Value:
                              Type:  string
                          Required:
                            key
                            operator
                            value
                            effect
                          Type:  object
                        Type:    array
                      Volume Mounts:
                        Properties:
                          Analytics:
                            Items:
                              Type:  string
                            Type:    array
                          Data:
                            Type:  string
                          Default:
                            Type:  string
                          Index:
                            Type:  string
                          Logs:
                            Type:  string
                        Type:      object
                    Type:          object
                  Server Groups:
                    Items:
                      Type:  string
                    Type:    array
                  Services:
                    Items:
                      Enum:
                        data
                        index
                        query
                        search
                        eventing
                        analytics
                      Type:      string
                    Min Length:  1
                    Type:        array
                  Size:
                    Minimum:  1
                    Type:     integer
                Required:
                  size
                  name
                  services
                Type:      object
              Min Length:  1
              Type:        array
            Software Update Notifications:
              Type:  boolean
            Tls:
              Properties:
                Static:
                  Properties:
                    Member:
                      Properties:
                        Server Secret:
                          Type:  string
                      Type:      object
                    Operator Secret:
                      Type:  string
                  Type:      object
              Type:          object
            Version:
              Pattern:  ^([\w\d]+-)?\d+\.\d+.\d+(-[\w\d]+)?$
              Type:     string
            Volume Claim Templates:
              Items:
                Properties:
                  Metadata:
                    Properties:
                      Name:
                        Type:  string
                    Required:
                      name
                    Type:  object
                  Spec:
                    Properties:
                      Resources:
                        Properties:
                          Limits:
                            Properties:
                              Storage:
                                Type:  string
                            Required:
                              storage
                            Type:  object
                          Requests:
                            Properties:
                              Storage:
                                Type:  string
                            Required:
                              storage
                            Type:  object
                        Type:      object
                      Storage Class Name:
                        Type:  string
                    Required:
                      resources
                      storageClassName
                    Type:  object
                Required:
                  metadata
                  spec
                Type:  object
              Type:    array
          Required:
            baseImage
            version
            authSecret
            cluster
            servers
  Version:  v1
  Versions:
    Name:     v1
    Served:   true
    Storage:  true
Status:
  Accepted Names:
    Kind:       CouchbaseCluster
    List Kind:  CouchbaseClusterList
    Plural:     couchbaseclusters
    Short Names:
      couchbase
      cbc
    Singular:  couchbasecluster
  Conditions:
    Last Transition Time:  2019-04-15T21:00:28Z
    Message:               no conflicts found
    Reason:                NoConflicts
    Status:                True
    Type:                  NamesAccepted
    Last Transition Time:  <nil>
    Message:               the initial names have been accepted
    Reason:                InitialNamesAccepted
    Status:                True
    Type:                  Established
  Stored Versions:
    v1
Events:  <none>

@davisford
Copy link

$ kc get crd -o yaml
apiVersion: v1
items:
- apiVersion: apiextensions.k8s.io/v1beta1
  kind: CustomResourceDefinition
  metadata:
    creationTimestamp: "2019-04-15T21:00:28Z"
    generation: 1
    name: couchbaseclusters.couchbase.com
    resourceVersion: "1019"
    selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/couchbaseclusters.couchbase.com
    uid: 7fa36465-5fc1-11e9-868c-6677e3d2572b
  spec:
    conversion:
      strategy: None
    group: couchbase.com
    names:
      kind: CouchbaseCluster
      listKind: CouchbaseClusterList
      plural: couchbaseclusters
      shortNames:
      - couchbase
      - cbc
      singular: couchbasecluster
    scope: Namespaced
    validation:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              adminConsoleServices:
                items:
                  enum:
                  - data
                  - index
                  - query
                  - search
                  - eventing
                  - analytics
                  type: string
                type: array
              antiAffinity:
                type: boolean
              authSecret:
                minLength: 1
                type: string
              baseImage:
                type: string
              buckets:
                items:
                  properties:
                    conflictResolution:
                      enum:
                      - seqno
                      - lww
                      type: string
                    enableFlush:
                      type: boolean
                    enableIndexReplica:
                      type: boolean
                    evictionPolicy:
                      enum:
                      - valueOnly
                      - fullEviction
                      - noEviction
                      - nruEviction
                      type: string
                    ioPriority:
                      enum:
                      - high
                      - low
                      type: string
                    memoryQuota:
                      minimum: 100
                      type: integer
                    name:
                      pattern: ^[a-zA-Z0-9._\-%]*$
                      type: string
                    replicas:
                      maximum: 3
                      minimum: 0
                      type: integer
                    type:
                      enum:
                      - couchbase
                      - ephemeral
                      - memcached
                      type: string
                  required:
                  - name
                  - type
                  - memoryQuota
                  type: object
                type: array
              cluster:
                properties:
                  analyticsServiceMemoryQuota:
                    minimum: 1024
                    type: integer
                  autoFailoverMaxCount:
                    maximum: 3
                    minimum: 1
                    type: integer
                  autoFailoverOnDataDiskIssues:
                    type: boolean
                  autoFailoverOnDataDiskIssuesTimePeriod:
                    maximum: 3600
                    minimum: 5
                    type: integer
                  autoFailoverServerGroup:
                    type: boolean
                  autoFailoverTimeout:
                    maximum: 3600
                    minimum: 5
                    type: integer
                  clusterName:
                    type: string
                  dataServiceMemoryQuota:
                    minimum: 256
                    type: integer
                  eventingServiceMemoryQuota:
                    minimum: 256
                    type: integer
                  indexServiceMemoryQuota:
                    minimum: 256
                    type: integer
                  indexStorageSetting:
                    enum:
                    - plasma
                    - memory_optimized
                    type: string
                  searchServiceMemoryQuota:
                    minimum: 256
                    type: integer
                required:
                - dataServiceMemoryQuota
                - indexServiceMemoryQuota
                - searchServiceMemoryQuota
                - eventingServiceMemoryQuota
                - analyticsServiceMemoryQuota
                - indexStorageSetting
                - autoFailoverTimeout
                - autoFailoverMaxCount
                type: object
              disableBucketManagement:
                type: boolean
              exposeAdminConsole:
                type: boolean
              exposedFeatures:
                items:
                  enum:
                  - admin
                  - xdcr
                  - client
                  type: string
                type: array
              logRetentionCount:
                minimum: 0
                type: integer
              logRetentionTime:
                pattern: ^\d+(ns|us|ms|s|m|h)$
                type: string
              paused:
                type: boolean
              serverGroups:
                items:
                  type: string
                type: array
              servers:
                items:
                  properties:
                    name:
                      minLength: 1
                      pattern: ^[-_a-zA-Z0-9]+$
                      type: string
                    pod:
                      properties:
                        automountServiceAccountToken:
                          type: boolean
                        couchbaseEnv:
                          items:
                            properties:
                              name:
                                type: string
                              value:
                                type: string
                            type: object
                          type: array
                        labels:
                          type: object
                        nodeSelector:
                          type: object
                        resources:
                          properties:
                            limits:
                              properties:
                                cpu:
                                  type: string
                                memory:
                                  type: string
                                storage:
                                  type: string
                              type: object
                            requests:
                              properties:
                                cpu:
                                  type: string
                                memory:
                                  type: string
                                storage:
                                  type: string
                              type: object
                          type: object
                        tolerations:
                          items:
                            properties:
                              effect:
                                type: string
                              key:
                                type: string
                              operator:
                                type: string
                              tolerationSeconds:
                                type: integer
                              value:
                                type: string
                            required:
                            - key
                            - operator
                            - value
                            - effect
                            type: object
                          type: array
                        volumeMounts:
                          properties:
                            analytics:
                              items:
                                type: string
                              type: array
                            data:
                              type: string
                            default:
                              type: string
                            index:
                              type: string
                            logs:
                              type: string
                          type: object
                      type: object
                    serverGroups:
                      items:
                        type: string
                      type: array
                    services:
                      items:
                        enum:
                        - data
                        - index
                        - query
                        - search
                        - eventing
                        - analytics
                        type: string
                      minLength: 1
                      type: array
                    size:
                      minimum: 1
                      type: integer
                  required:
                  - size
                  - name
                  - services
                  type: object
                minLength: 1
                type: array
              softwareUpdateNotifications:
                type: boolean
              tls:
                properties:
                  static:
                    properties:
                      member:
                        properties:
                          serverSecret:
                            type: string
                        type: object
                      operatorSecret:
                        type: string
                    type: object
                type: object
              version:
                pattern: ^([\w\d]+-)?\d+\.\d+.\d+(-[\w\d]+)?$
                type: string
              volumeClaimTemplates:
                items:
                  properties:
                    metadata:
                      properties:
                        name:
                          type: string
                      required:
                      - name
                      type: object
                    spec:
                      properties:
                        resources:
                          properties:
                            limits:
                              properties:
                                storage:
                                  type: string
                              required:
                              - storage
                              type: object
                            requests:
                              properties:
                                storage:
                                  type: string
                              required:
                              - storage
                              type: object
                          type: object
                        storageClassName:
                          type: string
                      required:
                      - resources
                      - storageClassName
                      type: object
                  required:
                  - metadata
                  - spec
                  type: object
                type: array
            required:
            - baseImage
            - version
            - authSecret
            - cluster
            - servers
    version: v1
    versions:
    - name: v1
      served: true
      storage: true
  status:
    acceptedNames:
      kind: CouchbaseCluster
      listKind: CouchbaseClusterList
      plural: couchbaseclusters
      shortNames:
      - couchbase
      - cbc
      singular: couchbasecluster
    conditions:
    - lastTransitionTime: "2019-04-15T21:00:28Z"
      message: no conflicts found
      reason: NoConflicts
      status: "True"
      type: NamesAccepted
    - lastTransitionTime: null
      message: the initial names have been accepted
      reason: InitialNamesAccepted
      status: "True"
      type: Established
    storedVersions:
    - v1
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

@davisford
Copy link

I built your v0.1.83 and it still has the same issue, strangely. Although I can go in an do kubectl create -f couchbase-cluster.yaml and that same YAML works.

I wonder if there's a sequence problem here? I'm blasting all of it with Terraform to create them all. Some things I'm using init containers to wait until the cluster is up before trying to add an RBAC user via a job, and start the sync gateway containers.

I wonder if submitting the cluster yaml job immediately precedes the creation of the CRD from the operator? That's why it is failing. Maybe I need to put an init container or pause for a bit while the operator does its thing first?

@lawrencegripper
Copy link
Owner

Yup I think you've hit the nail on the head with that one. The operator hasn't yet created the CRD so when this provider tries to create it it doesn't exist.

I tested out by adding a test case here and with the CRD in place it does work correctly.

Options:

  1. Use sleeps in local-exec bits to get this working
  2. Add a retry option to the k8s_raw provider which means it retries creation of a resource on failure a certain number of times with a backoff in between.

@lawrencegripper
Copy link
Owner

PR with couchbase test here: #18

@lawrencegripper
Copy link
Owner

@davisford so I've done some more testing and it looks like even with depends_on specified the timing of creating the crd definition and then an instance of it becomes an issue.

I've added retry like so, this will do an exponential backoff style retry and all creates which resolves the issue.

provider "k8sraw" {
  create_retry_count = 15
}

Just merging the change now so should be a build shortly for you to test.

@davisford
Copy link

davisford commented Apr 20, 2019

@davisford so I've done some more testing and it looks like even with depends_on specified the timing of creating the crd definition and then an instance of it becomes an issue.

I've added retry like so, this will do an exponential backoff style retry and all creates which resolves the issue.

provider "k8sraw" {
  create_retry_count = 15
}

Just merging the change now so should be a build shortly for you to test.

Nice...I won't be able to get to it until Monday, but thanks for the great support. I'm now utilizing init containers on jobs, etc. to get what I need. Spinning up a couch cluster is rather complicated. You first have to spawn the operator, then feed it a job to create the cluster (i.e. the CRD yaml that I'm using your provider for). Then I have to spawn a job to create an RBAC user for their sync gateway...using an init container to wait for the cluster to come up (also using your provider to submit jobs)...then I can spawn the sync gateway for their mobile client.

FWIW -- if anyone else lands here trying to build couch terraform scripts, at least as of today - the whole thing can't be done without a couple extra jobs. I added the k8s feature to TTL expire jobs, b/c I got tired of having to manually delete all these zombie pods, but then I realized if you do so, terraform destroy is broken -- mainly b/c it cannot undo jobs that have already been deleted.

Handling things like one-off jobs in Terraform is an interesting puzzle to solve. Wonder if anyone else has run into the problem and how they are addressing it?

@lawrencegripper
Copy link
Owner

Makes sense, thanks for coming back and sharing. I'll close this one off now as while we haven't solved for couchbase the provider does now support CRDs for other users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants