Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: support k8s 1.22 and upgrade dependencies #50

Merged
merged 5 commits into from
Aug 18, 2021

Conversation

LucasRoesler
Copy link
Member

@LucasRoesler LucasRoesler commented Jul 31, 2021

Description

  • Mimic the update-codegen.sh implementation from Flagger, this implementation handles modules correctly.

  • The controller code-generator is not compatible with modules and vendor, so this removes the vendor folder and all of the go flags that set the vendor mode.

  • Update to client-go 0.21.3, which is the latest version with v1beta1 networking support.

  • Create v1 and v2 sub-packages for the controller
    The controller package now contains all common code for the controller.

    The v1 package uses the typed client for the extensions/v1beta1 ingress
    and defines the sync handler responsible for creating and updating
    the ingress.

    The v2 package uses the typed client for the networking/v1 ingress and
    defines the the sync handler responseible for creation and updating
    the ingress.

  • Add a helper function to discover the cluster capabilities and use
    this to determine which controller to start.

Motivation and Context

  • I have raised an issue to propose this change (required)

Resolves #49

How Has This Been Tested?

WIP

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Impact to existing users

None

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

- Upgrade k8s client-go to version 1.19
- Create v1 and v2 sub-packages for the controller
  The controller package now contains all common code for the controller.

  The v1 package uses the typed client for the extensions/v1beta1 ingress
  and defines the sync handler responsible for creating and updating
  the ingress.

  The v2 package uses the typed client for the networking/v1 ingress and
  defines the the sync handler responseible for creation and updating
  the ingress.

- Add a helper function to discover the cluster capabilities and use
  this to determine which controller to start.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Mimic the `update-codegen.sh` implementation from Flagger, this
implementation handles modules correctly.

The controlle code-generator is not compatible with modules and vendor,
so this removes the vendor folder and all of the go flags that set the
vendor mode.

Update to client-go 0.21.3, which is the latest version with v1beta1
networking support.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Convert the tests for MakeAnnotations to a table driven test and add
cases for TLS and Skipper

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
1. Readd the vendor folder and revert changes to the Dockerfile
2. Create a new pattern for installing the k8s.io/code-gen tooling. This
   uses a "submodule" for defining the dependency so that we can use
   `go mod download` independently of the main peoject and vendor
   folder. This allows us to use native Go tooling and minimize the
   amount of custom scripting we need to write and maintain.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
@LucasRoesler LucasRoesler marked this pull request as ready for review August 14, 2021 14:40
@LucasRoesler
Copy link
Member Author

@alexellis i made the two requested changes

  1. the easy one is just renaming the controller subpackages to v1beta1 and v1 to match the networking api group they use
  2. re-adding the vendor folder and adding an alternative technique for installing and using code-gen. my approach mimics the approach in https://github.com/bwplotka/bingo by creating a go-submodule that depends on the correct code-gen version. This allows us to use go mod download -modfile=... meaning we can just use the codegen from the module cache and we don't need to invent any new tooling for fetching and managing it, it is just the native go tooling.

@LucasRoesler
Copy link
Member Author

A pre-built image is available at ghcr.io/lucasroesler/ingress-operator:pr-50

@LucasRoesler
Copy link
Member Author

I tested this in kind with k8s 1.19 using these files

# cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
  - containerPort: 31112 # this is the NodePort created by the helm chart
    hostPort: 8080 # this is your port on localhost
    protocol: TCP
# test.yaml
apiVersion: openfaas.com/v1alpha2
kind: FunctionIngress
metadata:
  name: nodeinfo
  namespace: openfaas
spec:
  domain: "nodeinfo.myfaas.club"
  function: "nodeinfo"
  ingressType: "nginx"
  path: "/v1/profiles/(.*)"

and then

$ kind create cluster --config=cluster.yaml
$ arkade install openfaas \
	--basic-auth=false \
	--clusterrole \
	--ingress-operator \
	--set ingressOperator.image=ghcr.io/lucasroesler/ingress-operator:pr-50


$ faas-cli store deploy nodeinfo
$ kubectl apply -f test.yaml
$ kubectl get ing
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
NAME       CLASS    HOSTS                  ADDRESS   PORTS   AGE
nodeinfo   <none>   nodeinfo.myfaas.club             80      5s

I then upgraded kind and used the latest k8s and got the same results, the ingress was created as expected

Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

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

LGTM, I like the simple solution of using the .tools folder. Nicely done.

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

Successfully merging this pull request may close these issues.

Update to latest API group for Ingress to support K8s 1.22+
2 participants