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

feat: xfn v1beta implementation #1

Closed
wants to merge 3 commits into from

Conversation

phisco
Copy link
Collaborator

@phisco phisco commented Aug 11, 2023

Initial move of xfn from the in-tree implementation, only implementing the new v1beta1 interface.

Signed-off-by: Philippe Scorsolini <[email protected]>
@phisco phisco requested a review from negz August 11, 2023 08:05
Signed-off-by: Philippe Scorsolini <[email protected]>
@phisco
Copy link
Collaborator Author

phisco commented Aug 11, 2023

To test it:

kind create cluster

make -j2 build.all

docker tag build-<...>/xfn-oci-<arch> crossplane/xfn-oci:v0.0.0

kind load docker-image crossplane/xfn-oci:v0.0.0

kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: xfn
  name: xfn
spec:
  containers:
  - image: crossplane/xfn-oci:v0.0.0
    name: xfn
    ports:
    - containerPort: 1234
    volumeMounts:
    - mountPath: /xfn
      name: xfn-cache
  volumes:
  - name: xfn-cache
    emptyDir:
      sizeLimit: 1Gi
  restartPolicy: Always
EOF

kubectl port-forward xfn 1234:1234

Now, given an image phisco/xfn-output-v1beta1:v0.4, which was built using the following Dockerfile:

FROM alpine:3.18
RUN apk add --no-cache jq
ENTRYPOINT ["/bin/sh", "-c", "jq '.desired.composite.resource.labels |= {\"labelizer.xfn.crossplane.io/processed\": \"true\"} + .'"]

If we run the following command:

grpcurl -plaintext -d @ localhost:1234 apiextensions.fn.proto.v1beta1.FunctionRunnerService.RunFunction <<EOM
{
  "desired": {
    "composite": {
      "resource": {
        "something": "something"
      }
    }
  },
  "input": {
    "spec": {
      "image": "phisco/xfn-output-v1beta1:v0.4"
    }
  }
}
EOM

We get back:

{
  "desired": {
    "composite": {
      "resource": {
          "labels": {
                "labelizer.xfn.crossplane.io/processed": "true"
              },
          "something": "something"
        }
    }
  }
}

Which is indeed the desired output.

Copy link
Member

@negz negz left a comment

Choose a reason for hiding this comment

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

@phisco If it's not too hard to do, could you "refactor" this PR such that it starts with a plain copy of the code from c/c in one commit, with your changes as an overlay in separate commits? This will make it easier to just review the changes.

"github.com/crossplane/crossplane/apis/apiextensions/fn/proto/v1beta1"

"github.com/upbound/xfn-oci/cmd/xfn-oci/internal/config"
v1beta12 "github.com/upbound/xfn-oci/internal/container"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being imported as v1beta12?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess the IDE picked that name at some point, I will review import aliases once I rebase it on top of #2.

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/uuid"
runtime "github.com/opencontainers/runtime-spec/specs-go"
proto2 "google.golang.org/protobuf/proto"
Copy link
Member

Choose a reason for hiding this comment

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

Why is this proto2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same as above

@phisco
Copy link
Collaborator Author

phisco commented Aug 11, 2023

I did a few more changes than the minimum required ones, but I think I still have a branch with both the implementation working with just a switch, so I can definitely try to make it more understandable.

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.

2 participants