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

Feature: CRD, Controller and Webhook For Hot News #12

Merged
merged 130 commits into from
Sep 6, 2024

Conversation

werniq
Copy link
Owner

@werniq werniq commented Aug 14, 2024

Introduce Kubebuilder Controller, CRD, and Webhook for Hot News

Overview

This pull request introduces a new Kubebuilder Controller, Custom Resource Definition, and a Validating Webhook for Retrieving news from Go-Gator Server.
This operator validates fields specified in Spec group, and constructs a URL to retrieve news within given range, with specified keywords, or from particular Feeds.
Additionally, it listens for updates in feed-group-source Config Map, and Feeds CRD, and if anything was changed it is considered as changing state in HotNews.

Key Changes

  • Added Controller for HotNews
  • Defined the Hotnews CRD with fields for specifying arguments for news retrieval
  • Implemented logic in the controller to retrieve news by parameters specified in HotNews.Spec group
  • A mutating webhook to set titlesCount to 10, and validating webhook to verify that date range is valid (dateStart is before dateEnd), either feeds or feedGroups are specified, and if feedGroups were specified, they are valid.
  • Implemented Unit Tests for Webhook and Controller

Details

  • Controller: Implemented logic to retrieve latest news. The controller has a Reconcile function, which is triggered when Feed is created, updated or deleted. Also, the Reconcile func is called when we have updates in feed-group-source config map, or updates with Feeds CRD, if it is associated with HotNews.Spec.Feeds

  • Custom Resource Definition: Defines the schema for a HotNews resource, which includes the fields required for fetching news like keywords, dateStart or dateEnd.

  • Mutating Webhook: A mutating webhook which sets following values by default:

    • SummaryConfig.titlesCount , which specifies amount of titles that should be stored in status.articlesTitles, is set to 10
  • Validating Webhook: A validating webhook which checks for:

    • Date range Validation: Ensures that the HotNews date range is valid - dateStart should be before dateEnd
    • Feeds Validation: Verifies that values specified in feedGroups are valid (e.g. exist in feed-group-source)

Example:
image
image

Result:
image

Config Map Data:
image

Pull Request Template

Checklist before submitting a PR for a review

  • PR title conforms to Conventional Commit pattern
  • Build and test locally
  • Update documentation
  • Ensure all errors are handled properly
  • Check variable & func names
  • Verify that tested positive and negative scenarios in all tests

werniq and others added 30 commits August 6, 2024 07:04
@werniq werniq merged commit 3c37518 into feature/operator-and-crd Sep 6, 2024
1 of 2 checks passed
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