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

Migrating config entries into custom resources #419

Merged
merged 1 commit into from
Jan 25, 2021
Merged

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented Jan 12, 2021

Support annotation consul.hashicorp.com/migrate-entry on custom
resources that will allow an existing config entry to be migrated onto
Kubernetes. The config entry from then on will be managed by Kubernetes.

This will support existing users of the Helm chart that already have
config entries in Consul and allow them to migrate to CRDs.

How I've tested this PR:

  • code
  • manual testing

How I expect reviewers to test this PR:

  1. spin up cluster with

    global:
      name: consul
      imageK8S: ghcr.io/lkysow/consul-k8s-dev:jan12
    server:
      replicas: 1
    connectInject:
      enabled: true
    controller:
      enabled: true
  2. create a service-defaults config:

    kubectl exec consul-server-0 -- echo '{"kind": "service-defaults", "name": "foo", "protocol": "http"}' | consul config write -
  3. read it

    kubectl exec consul-server-0 -- consul config read -kind service-defaults -name foo
    {
        "Kind": "service-defaults",
        "Name": "foo",
        "Protocol": "http",
        "MeshGateway": {},
        "Expose": {},
        "CreateIndex": 973,
        "ModifyIndex": 973
    }
  4. create a matching CR:

    cat <<EOF | kubectl apply -f -
    apiVersion: consul.hashicorp.com/v1alpha1
    kind: ServiceDefaults
    metadata:
      name: foo
    spec:
      protocol: "http"
    EOF
  5. check that it's not syncing:

    kubectl describe servicedefaults foo
    ...
    Status:
      Conditions:
        Last Transition Time:  2021-01-12T21:03:29Z
        Message:               config entry managed in different datacenter: ""
        Reason:                ExternallyManagedConfigError
        Status:                False
        Type:                  Synced
  6. add the annotation:

    cat <<EOF | kubectl apply -f -
    apiVersion: consul.hashicorp.com/v1alpha1
    kind: ServiceDefaults
    metadata:
      name: foo
      annotations:
        "consul.hashicorp.com/migrate-entry": "true"
    spec:
      protocol: "http"
    EOF
  7. check that it's synced:

    kubectl describe servicedefaults foo
    ...
    Status:
      Conditions:
        Last Transition Time:  2021-01-12T21:04:37Z
        Status:                True
        Type:                  Synced
  8. check it's got the expected metadata

    kubectl exec consul-server-0 -- consul config read -kind service-defaults -name foo
    {
        "Kind": "service-defaults",
        "Name": "foo",
        "Protocol": "http",
        "MeshGateway": {},
        "Expose": {},
        "Meta": {
            "consul.hashicorp.com/source-datacenter": "dc1",
            "external-source": "kubernetes"
        },
        "CreateIndex": 973,
        "ModifyIndex": 1065
    }

Checklist:

  • Tests added
  • CHANGELOG entry added (HashiCorp engineers only, community PRs should not add a changelog entry)

@lkysow lkysow force-pushed the crd-migration branch 2 times, most recently from 6338946 to 829f6bf Compare January 12, 2021 20:16
@lkysow lkysow marked this pull request as ready for review January 12, 2021 22:55
@lkysow lkysow requested review from a team, ndhanushkodi and kschoche and removed request for a team January 12, 2021 22:55
Copy link
Contributor

@kschoche kschoche left a comment

Choose a reason for hiding this comment

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

excellent work!

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks for the detailed testing steps, they worked!

Support annotation consul.hashicorp.com/migrate-entry on custom
resources that will allow an existing config entry to be migrated onto
Kubernetes. The config entry from then on will be managed by Kubernetes.

This will support existing users of the Helm chart that already have
config entries in Consul and allow them to migrate to CRDs.
@lkysow
Copy link
Member Author

lkysow commented Jan 25, 2021

The test failure is a flake fixed in #421.

@lkysow lkysow merged commit 27bd34d into master Jan 25, 2021
@lkysow lkysow deleted the crd-migration branch January 25, 2021 20:25
ndhanushkodi pushed a commit to ndhanushkodi/consul-k8s that referenced this pull request Jul 9, 2021
tls-init-cleanup can run if pre-install fails
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

Successfully merging this pull request may close these issues.

3 participants