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

api in pairs: main && test apis: action, state, specs: bulk specs #20

Open
AmitKumarDas opened this issue Jul 12, 2024 · 0 comments
Open

Comments

@AmitKumarDas
Copy link
Collaborator

AmitKumarDas commented Jul 12, 2024

  • golang module: relm
  • golang package: relm/pkg/carvel
  • golang file: relm/pkg/carvel/bundle.go
  • last updated date: 23/JUL/2024
package carvel

type AnySpecsValidate interface {
  // public; external clients can invoke
  ValidateSpecs() error
}

type AnyBundlePush interface {
  // AnySpecsValidate ensures the instance of AnyBundlePush can be validated
  AnySpecsValidate

  // private; avoid custom implementations by external client
  pushBundle() (BundleResult, error)
}
type AnyBundlePushAssert interface {
  AnyBundlePush

  assertBundlePush() (AssertResult, error)
}
var _ AnyBundleCreate = &NestedBundleCreateSpecs{}
var _ AnyBundlePush = &BundlePushSpecs{}
var _ AnyPackageCRResolve = &PackageCRResolveSpecs{}
var _ AnyFileCopy = &FileCopySpecs{}
// Copy Package Metadata CR yaml to output location
var myFile1 = FileCopySpecs {
  Source: "path/to/component/package-meta-cr.yaml",
  Destination: "nested/bundle/config/component-v1.0.0/package-meta-cr.yaml",
}
// Resolve Package CR yaml & copy the resolved yaml to output location
var myPkgCR2 = PackageCRResolveSpecs {
  Method: YttFileOut, // Low level operation; declarative
  Source: "path/to/component/package.yaml",
  Destination: "nested/bundle/config/component/package.yaml", 
  KeyValues: map[string]string {
    "version": "v1.0.0",
    "image": "address/component_bundle@sha256:digestxxxx",
  },
}
// Push a bundle file (that was created earlier) to registry, 
// Then resolve the corresponding Package CR yaml using above registry endpoint, 
// Finally copy the resolved Package CR yaml to declared output location
var myBundle1 = &BundlePushSpecs {
  Method: ImgpkgCopyTarToRepo, // Low level operation; declarative
  Source: BundleSourceSpecs {
    BundleFilePath: "${GOBUILD_RELM_PATH}/bundle.tar.gz",
  },
  Destination: BundleDestinationSpecs {
    Address: "localhost:5000",
    BundlePath: "bundles/relm_bun",
    BundleTag: "v1.0.0",    
  },
  PackageCR: &PackageCRResolveSpecs { // [optional];
    Method: YttFileOut,
    Source: "relm/package.yaml", // templated file
    Destination: "nested/bundle/config/relm/package.yaml", 
    KeyValues: map[string]string {
      "version": "v1.0.0",
      "image": "localhost:5000/bundles/relm_bun:v1.0.0",
    },
    KeyValueRefs: map[string]string { // Alternative to KeyValues
      "version": LookupBundleTag,
      "image": LookupBundleURLTag,
    },
    refValues: map[string]string { // Private/Internal; filled up by BundleSpecs
      LookupBundleTag: "v1.0.0",
      LookupBundleURLTag: "localhost:5000/bundles/relm_bun:v1.0.0",
      LookupBundleURLDigest: "localhost:5000/bundles/relm_bun@sha256:digestxxx",
    },
  },
}
  • Summary
- One interface per action i.e. API
- Interfaces determine the main behaviour i.e. API
- Use prefix `Any` for interface names
- Use suffix `Specs` for struct names
- One struct (i.e. specs) for multiple interfaces wherever possible
- Every API should have corresponding Assert API
- Read (i.e. Maintainability) over Write (i.e. Implementation)
  - Distinct, Non ambiguous, Easy to understand
- Use verbose field names in Specs struct
- Use verbose method / function names
  - E.g.: getXXX, runXXX, createXXX, newXXX, etc.
- Keywords:
  - `XXXState` # PackageCRState, etc.; Multiple States per Action
  - `PostOperation` # PreOperation, etc.
  - `Method` # ImgpkgCopy, Ytt, CranePull, etc.
    - Names the `Low Level Operations`
  - `Target` # w.r.t Assert i.e. TargetUnderTest
@AmitKumarDas AmitKumarDas changed the title design api & test api: action, state & specifications design: main api & test api: action, state, specs & bulk specs Jul 12, 2024
@AmitKumarDas AmitKumarDas changed the title design: main api & test api: action, state, specs & bulk specs design: main api && test api: action, state, specs & bulk specs Jul 12, 2024
@AmitKumarDas AmitKumarDas changed the title design: main api && test api: action, state, specs & bulk specs api in pairs: main api && test api: action, state, specs & bulk specs Jul 13, 2024
@AmitKumarDas AmitKumarDas changed the title api in pairs: main api && test api: action, state, specs & bulk specs api in pairs: main api && test api: action, state, specs: bulk specs Jul 13, 2024
@AmitKumarDas AmitKumarDas changed the title api in pairs: main api && test api: action, state, specs: bulk specs api in pairs: main && test apis: action, state, specs: bulk specs Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant