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

Add new NonClusterHost resource for log ingestion #3485

Merged
merged 6 commits into from
Sep 12, 2024

Conversation

hjiawei
Copy link
Contributor

@hjiawei hjiawei commented Sep 1, 2024

Description

This change introduces a new NonClusterHost custom resource for Calico Enterprise to support non-cluster hosts log ingestion.

For PR author

  • Tests for change.
  • If changing pkg/apis/, run make gen-files
  • If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

@marvin-tigera marvin-tigera added this to the v1.36.0 milestone Sep 1, 2024
@hjiawei hjiawei marked this pull request as ready for review September 3, 2024 18:20
@hjiawei hjiawei requested a review from a team as a code owner September 3, 2024 18:20
// NonClusterHostSpec enables non-cluster hosts to connect to a cluster.
type NonClusterHostSpec struct {
// Location of the log ingestion point for non-cluster hosts. example: https://1.2.3.4:443
Endpoint string `json:"endpoint"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a required field. Should we add:
json:"endpoint" validate:"required"

Copy link
Contributor

@dimitri-nicolo dimitri-nicolo Sep 4, 2024

Choose a reason for hiding this comment

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

It might be worth writing a custom validator, so that the string input that does not match the a predefined regex pattern prints an error at the time of creation.

This might work: // +kubebuilder:validation:Pattern=^https?://.+$``

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Validation pattern is added to the endpoint field.

Copy link
Member

Choose a reason for hiding this comment

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

Since NonClusterHostSpec is not a required field, please mind that it is still possible to create this resource without the Endpoint field. Does that have any implications for the feature? Should the controller still validate that the field exists?

Copy link
Member

Choose a reason for hiding this comment

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

NonClusterHostSpec isn't required, but it's also not a pointer, which means it will be present regardless and so this field should always be defaulted by the kubebuilder validation IIUC

Copy link
Member

Choose a reason for hiding this comment

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

I applied the CRD to my kind cluster:

$ k apply -f nonclust.yaml 
The NonClusterHost "default" is invalid: spec.endpoint: Required value

 1   12:17:55   ~/dev/kind    
$ cat nonclust.yaml 
kind: NonClusterHost
apiVersion: operator.tigera.io/v1
metadata:
  name: default
spec: {}

But then:

$ k apply -f nonclust.yaml 
nonclusterhost.operator.tigera.io/default configured
 0   12:18:26   ~/dev/kind    
$ cat nonclust.yaml 
kind: NonClusterHost
apiVersion: operator.tigera.io/v1
metadata:
  name: default
spec: null

Copy link
Member

Choose a reason for hiding this comment

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

hmm, guess I was wrong about that. Surprised that spec: null is valid at all considering the spec isn't a pointer.

Copy link
Member

Choose a reason for hiding this comment

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

It is identical to this:

kind: NonClusterHost
apiVersion: operator.tigera.io/v1
metadata:
  name: default

// Check if non-cluster host log ingestion is enabled.
// non-cluster hosts will only forward logs to a standalone or a managed cluster.
var nonclusterhost *operatorv1.NonClusterHost
if managementCluster == nil {
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering if there is any harm in removing this if-statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If a nonclusterhost resource is accidentally applied to a management cluster, this check prevents opening the ingestion endpoint.

Copy link
Member

Choose a reason for hiding this comment

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

I meant to say that I don't really see the problem in having a management cluster that also has non cluster hosts working at the same time.

Copy link
Member

Choose a reason for hiding this comment

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

At a minimum, I would prefer if we inverted this check - i.e., "If both are specified, error" instead of silently ignoring an unsupported configuration.

I'm fine with erroring for now if MCM is out of scope, but also fine to allow it in management clusters if we think it will come relatively for free.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spec.endpoint is validated in the manager controller. When NonClusterHost resource is applied to the cluster and the endpoint filed is an invalid URL, manager controller will be degraded.

The managementCluster == nil check is also removed because management cluster should support this feature.

Copy link
Member

@rene-dekker rene-dekker left a comment

Choose a reason for hiding this comment

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

lgtm

@rene-dekker rene-dekker merged commit 87f2809 into tigera:master Sep 12, 2024
5 checks passed
@hjiawei hjiawei deleted the non-cluster-hosts branch September 12, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants