I could not understand what the package can do, the offical doc show nothing about unstructured. What the package used for ? Is it used for converting map[string]interface{} to K8S Obj ?
https://godoc.org/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured
It looks like unstructured provides an interface to kubernetes objects, when you don't know object type upfront, i.e. dynamic package in client-go uses it extensively
As #kseniia-churiumova suggested it is used when you don't know the object type. Here is the use case to understand it better. Let us say your organisation has a policy that all Kubernetes object must have annotation "owner" with value pointing to email ID of a person or group. You have tasked with finding all the resources that violates this policy.
You can have a configuration file that has list of GroupVersionKind and use unstructured to query them. If a new type needs a check you can add to configuration without changing the code.
Note: This is just an example. In production you will have to use something like Gatekeeper that implements OPA specification to enforce policies.
Related
I'd like to be able to generate an urn based on the current stack, project and resource type. This would be handy when renaming resources, where the aliases options requires a full urn to make the link between resources.
I've got the following:
`urn:pulumi:${pulumi.getStack()}::${pulumi.getProject()}::kubernetes:storage.k8s.io/v1:StorageClass::cluster-enable-ssd`
I'd like to generate the kubernetes:storage.k8s.io/v1:StorageClass part given an arbitrary pulumi Resource class, e.g. in this case k8s.storage.v1.StorageClass. The Resource class itself has name on it, but that only returns StorageClass.
Is there any way to get the global, unique identifier for a pulumi Resource type?
It's a bit hacky but you can get it like this (in Node.js):
(k8s.storage.v1.StorageClass as any).__pulumiType
I'm defining my own Puppet class, and I was wondering if it is possible to have an array variable which contains a list of all files in a specific directory. I was wondering to have a similar syntax like below, but didn't found a way to make it work.
$dirs = Dir.entries('C:\\Program Files\\Java\\')
Does anyone how to do it in a Puppet file?
Thanks!
I was wondering if it is possible to have an array variable which contains a list of all files in a specific directory.
Information about the current state of the machine to be configured is conveyed to the catalog compiler via facts. These are available to your classes as top-scope variables, and Puppet (or Facter, actually) provides ways to define your own custom facts. That's a link into the Facter 3 manual, but similar applies to earlier versions. Do not overlook the rest of the Facter documentation, which has more relevant information on this topic.
On the other hand, information about the machine providing catalog-building services -- the master in a master / agent setup -- can be obtained by writing and calling a custom function. This is rarely what you actually want, but it's worth mentioning because you might one day want a custom function for some other purpose.
Let's say I have a struct definition like this:
struct SomeStruct {
1: optional binary content;
2: optional binary newConetent;
}
What is the best practice to deprecate the first field ("content"), without affecting deployment? The deployment of the new code will be into multiple applications that is using this thrift structure? (Assuming some applications are still using the "content" field before the deployment)?
Thank you!
The recommended solution is to comment out the field but leave it in the IDL. This prevents the field ID from becoming reused later for sth. else which then of course would produce incompatibilities.
If "in use by clients" means that they are accessing the outdated field for RPC only, that's not a problem w/regard to Thrift. Thrift will behave just like with a new field.
If however you mean that the field is used for serialization and the old data contain relevant information that needs to be converted somehow into the new format, you will have to leave the field active in the IDL. You may consider renaming the field in order to make it visible to the target audience of your IDL.
I used the suggested approach in this question to return HATEOAS formatted outputs that match those returned by spring-data-rest. It works good, but is there a way to avoid boiler plate code to create entity resource assemblers like the QuestionResourceAssembler in the referenced question, if I only want to add 'self' links using the id to all entities? Perhaps using ResourceAssemblerSupport?
The easiest way is to simply use the Resource wrapper type:
Resource<Person> personResource = new Resource<>(person);
personResource.addLink(…);
personResource.addLink(…);
Links can be created either by simply instantiating them (i.e. new Link("http://localhost/foo", "relation") or by using the ControllerLinkBuilder which allows you to point to Controller methods for obtain a reverse mapping. See this section of the Readme for details.
Is it recommended that we place an Import on a property instead of a field? I tried it on a field and it is working but Resharper is telling me a warning that the field was never initialized.
ReSharper doesn't recognize that MEF will be setting the variable and since there is no guarntee that MEF will be setting the variable (example if it isn't put into a container for example), so it is reasonable for ReSharper to warn about this. You can either ignore it or simply initialize the field to null (or default(T)).
As for whether or not you should use a property or field I think using a field is fine (assuming it is not public). I generally reserve properties for things I want to expose publicly. One special case to consider here is that there are some issues having Imports on private members in low trust scenarios like SL or paritial trust because MEF uses reflection and you cannot use private reflection in some of those scenarios.